You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a convention to represent a collection of items where we know we have at least one item as a tuple of the first item and the rest. However, this representation is awkward if we need to do additional list processing, as we need to deconstruct the tuple and then :: it, which tends to be awkward in pipelines. Hence this helper can help pipelined code:
which is not terrible, but certainly not pleasant to type (and autocomplete doesn't help much, but probably copilot can manage).
It's worse when in the middle of a pipeline where you end up with a non-empty list on its own, where you need a bare lambda in a pipeline - which is always a bit awkward looking.
The other option you have is of course Tuple.Extra.apply (::), but that is perhaps too clever to think of on the spot?
Alternatives
Name it List.Extra.cons as the logical opposite of List.Extra.uncons. It's shorter and perhaps less confusing w.r.t. dedicated non-empty list custom types.
Not bother. In general adding relatively trivial functions like this for mere syntactic convenience is something I'd like to not encourage too much of, since I think we've already got the really useful ones covered and the rest tend to be more confusing than helpful. The only reason I'm proposing this one is that we already have a few functions that return non-empty lists (and are proposing more), and I've always disliked working with those as it made further processing more painful.
The text was updated successfully, but these errors were encountered:
List.Extra.fromNonEmpty : ( a, List a ) -> List a
It's a convention to represent a collection of items where we know we have at least one item as a tuple of the first item and the rest. However, this representation is awkward if we need to do additional list processing, as we need to deconstruct the tuple and then
::
it, which tends to be awkward in pipelines. Hence this helper can help pipelined code:Motivating use case
This is explained in the doc above.
Rationale
which is not terrible, but certainly not pleasant to type (and autocomplete doesn't help much, but probably copilot can manage).
It's worse when in the middle of a pipeline where you end up with a non-empty list on its own, where you need a bare lambda in a pipeline - which is always a bit awkward looking.
The other option you have is of course
Tuple.Extra.apply (::)
, but that is perhaps too clever to think of on the spot?Alternatives
List.Extra.cons
as the logical opposite ofList.Extra.uncons
. It's shorter and perhaps less confusing w.r.t. dedicated non-empty list custom types.The text was updated successfully, but these errors were encountered: