list-extra
list-extra copied to clipboard
code design thought
I noticed the signature of List.Extra.splitWhen
don't make completely sense:
-- current --
splitWhen : (a -> Bool) -> List a -> Maybe ( List a, List a )
splitWhen (\n -> n == 6) [ 1, 2, 3, 4, 5 ]
--> Nothing
-- problematic example --
case splitWhen someFunction list of
Nothing ->
-- do one thing
Just (left, []) ->
-- never happens
Just (left, headR :: queueR) ->
-- do something else
To me it makes more sense to remove the Maybe
and if the given function never returns True
then just give an empty list in Tuple.second
.
-- imo --
splitWhen : (a -> Bool) -> List a -> ( List a, List a )
splitWhen (\n -> n == 6) [ 1, 2, 3, 4, 5 ]
--> ([ 1, 2, 3, 4, 5 ], [])
-- problematic example --
case splitWhen someFunction list of
(left, []) ->
-- do one thing
(left, headR :: queueR) ->
-- do something else
Right now the behavior is kind of oddly combining with List.any
and there is a repeating of the information.
Thats a really good point. That is confusing.
If we go to a (List a, List a)
is it confusing that..
splitWhen fn []
--> ([], [])
?
Maybe not right? I feel like thats alright.
Without the Maybe
, the second list being empty would indicate that there was no point on which to split.
So far I like this idea of dropping the Maybe
from splitWhen