Closed showell closed 4 years ago
This seems closely related to #82 and #95, although the type is slightly different. Maybe we can pick up the discussion in #82 to keep things in one place.
As for the example that you included in your issue, I think using Parser.oneOf might lead to a more idiomatic solution (which I now see you mentioned in elm-community/maybe-extra#47).
Yeah, this was inspired by Parser.oneOf
, for sure. (The reason I don't directly use Parser.oneOf
is that sometimes I have non-Parser parsers for routes.)
I'll close this in favoar of #82. Thanks, @pzp1997! (P.S. See you in Philly tonight!)
The idea is that you have a function to apply to your elements, and you want the first value that satisfies the predicate, and you want to short-circuit as soon as you find a match. The problem with the current API (unless I'm missing something) is that you can only get the index or the element, so you end up having to recalculate your function. Hopefully the code below clarifies a typical use case.