Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code design thought #141

Open
staeter opened this issue Mar 5, 2021 · 1 comment
Open

code design thought #141

staeter opened this issue Mar 5, 2021 · 1 comment

Comments

@staeter
Copy link

staeter commented Mar 5, 2021

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.

@Chadtech
Copy link
Collaborator

Chadtech commented Mar 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants