dogweather
I’m parsing input, returning the successfully parsing items, and logging the parse errors. (In this app, this is the behavior I want: continue working with successful parses, and a log file with the errata.)
processed_sections = map(raw_sections, &new_section/1)
reduce(processed_sections, [], fn e, acc ->
case e do
{:error, msg} ->
Logger.warn(msg)
acc
{:ok, section} ->
acc ++ [section]
end
end)
Is there some more canonical way of working through the {:ok|:error} results?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
100phlecs
You can get rid of the
casestatement with anonymous function pattern matching:i.e.
or in your case
hst337
There are several ways to do this, but there is no “canonical” way.
Your solution has a problem with
++operator, which makes this whole solution beO(n^2)complexity. I’d suggest prepending to the head and then reversing the result (or using Enum.flat_map)awerment
Taking the opportunity for some bike shedding
… If you‘re not using the intermediate values, you could do it with some pipes:
dogweather
I noticed how generic my code is, and thinking about moving this to a separate function like Haskell’s
fromJustorcatMaybes: Data.Maybe (Does Elixir have a similar library?)So, e.g.,
dogweather
Yeah, that’s pretty good. And then I’d just refactor it by extracting the function:
Does Elixir have a library with functions like
catOks? (Searching…)awerment
I‘m not aware of one in the standard lib, but you already have most of it
Using ’Enum.filter/2’ would save you the need to reverse, though:
Edit: Ah, sorry, disregard the above, it would not unwrap the tuples.
Sorc96
I tend to prefer functions other than custom
reduce, so in this case, I would probably do someting like this:Seriously though, we need a standardized higher level way to work with
:okand:errortuples.cloudytoday
Towel (or specifically its recentmost fork) has it IIRC. Alternatively, calling Gleam’s
resultmodule would do the same. I have a personal helpers lib (a couple of them) with a whole bunch of utilities like this, but it’s not in the state where it would make sense to publish it. Anyways it wouldn’t take one more than a day or two to come up with one.al2o3cr
This can be golfed down even further by using
Enum.flat_mapto express the “map, but only keep some of them” idiom:Monad enthusiasts should be able to spot
Resultbeing transformed intoOptiontherecloudytoday
Options are not about binding/flatmapping lists, an
Optiontype would need to be represented as something like{:some, a} | :nothing, or did I misunderstand what you meant?