Closed c0m3tx closed 1 year ago
Some of our collegues brought to our attention that this implementation would make the type system inconsistent, in some way. We could have a Just []
and we would be therefore unable to ensure that the inner list has at least one element. A better signature for this function would be toMaybeList : List a -> Maybe (a, List a)
, which is exactly what uncons
does. We decided that correctness is more important, and we removed all instances of this function from our code 😄
Makes sense! Yes, it does seem like the correctness of uncons
is ideal. Thanks for the time and consideration you put into this.
Often times, when writing code for the UI, we get a list of elements to show. They have to be shown only if at least one element is available, so it would be useful to have a function which converts a
List a
in aMaybe (List a)
:list
has no elements, returnsNothing
list
has at least one element, returnsJust list
This allows, for instance
The code we currently use for this function is quite simple, and we believe it may be a nice addition to this lib. As far as we know, currently there is no way to achieve this using what is currently available.
I will do the implementation and open a PR, if you feel this could be useful 😄