|
|
|
|
|
by shakow
1863 days ago
|
|
> if a call at the beginning of the pipeline returns a tuple of `{:ok, result}` In my understanding, pipeline are mostly reserved for “unfailable” operations operating on raw data; whereas the where/else/do macro is more oriented towards errors handling; would it work better in your case? |
|
I think I gave a bad example, the better one would be a function returning datetime in the format of :erlang.localtime: `{{Year,Month,Day},{Hour,Min,Sec}}`. I would like to be able to use this value in a pipeline, by passing only a `{Hour, Min}` tuple to the next call in the pipeline.
With pattern_tap it looks like this:
Without - there are at least 3-4 ways of doing this, each with pros and cons, but all of them are more verbose than pattern_tap. If you want a single value only, there's `elem`, but if you need a few - you're out of luck. `destructure` only works on lists, and `match?` only return a boolean, not whatever was matched.`then` macro makes it a bit better, but you still need to create a lambda with the longhand syntax, which is exactly what I wanted to avoid, so it's hardly a solution, even though it may be the best way to do this for now...
EDIT: this is in contrast to Clojure, where maps and vectors are callable, and you get `juxt` in the stdlib. So it's not like pipelines in general can't support convenient extraction of subsets of data flowing through the pipe, it's just that Elixir decided not to support this.