4 ms·
If you’re chaining more than three or four things together I think you’re definitely doing something wrong but I’m not sure I’ve ever seen someone do that in El
by jolux 6y ago
If you’re chaining more than three or four things together I think you’re definitely doing something wrong but I’m not sure I’ve ever seen someone do that in Elixir.
- dnautics 6y agoNot an antipattern for nimble_parsec: https://github.com/ityonemo/zigler/blob/fe845a9fbbfef92da8aba99ffd599a2e6551e807/lib/zig/doc/parser.ex#L88 https://github.com/ityonemo/zigler/blob/fe845a9fbbfef92da8ab... Plus think of how much easier that pipe makes it for you to understand what is going on.
- jolux 6y agoThat’s a very beautiful usage of it. I hadn’t thought of it as a way to construct DSLs, but it makes a lot of sense here.
- owl57 6y agoLooks like Haskell-like do notation would be helpful.
- dnautics 6y agodo you feel like the code presented is broken? I don't. Could it be better? Maybe... But how much? Is it worth a whole new pattern to learn?
- cultofmetatron 6y agothe entire ecto api is built upon chaining statements together. I have a few queries that are 8-10 statements long.
- jolux 6y agoGood point, I don’t use Ecto so I wasn’t aware of this.
- Kaze404 6y agoMy longest pipe chain in Elixir so far (with ~1 year of usage) is this[1], where I build a GraphQL context from an HTTP session. I personally think it's clean enough, but your comment made me wonder if it can be better. [1] https://github.com/RodrigoLeiteF/craftup/blob/main/backend/lib/craftup_web/context.ex#L16 https://github.com/RodrigoLeiteF/craftup/blob/main/backend/l...
- 1_player 6y agoI disagree. I think a common antipattern is piping only one thing. This is good and readable: nuclear_missile |> open_hatch() |> open_fuel_lines() |> fire_thrusters(:all) |> configure_gps(%Coordinates{...}) This is unnecessary: word_count = words |> Enum.count() This is better: word_count = Enum.count(words) Pipes read like a list of bullet points. We can easily deal with up to a dozen bullet points, but a single bullet point is bad grammar style.