-
Notifications
You must be signed in to change notification settings - Fork 58
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
groupWhile should return a List of Nonempty, not a List of List #49
Comments
|
But is I'm not saying that the type of
|
@jvoigtlaender The return type for |
Okay, fine for |
@Chadtech |
Okay I see now @z5h . Yeah I was wrong. |
@pzp1997 made a suggestion of |
@pzp1997 's idea sounds good to me too. I think we should change the type signature of Thats not bad. Helpers arent bad. But it is added code that make things a tiny bit more complicated. So how about we also add something like @pzp1997 's idea of mapNonEmpty : (a -> b) -> (a, List a) -> (b, List b)
toNonEmpty : List a -> Maybe (a, List a)
fromNonEmpty : (a, List a) -> List a |
Ideally the following should hold true: myList
|> List.groupWhile f
|> List.map List.head -- I'm expecting a list of concretes, not Maybes. Otherwise the group should not even exist to start with! Not sure about the best way to implement that would be. We obviously can't re-use the current I ended up simply copying the existing implementation and modifying it with Nonempty like so for my own needs: groupWhile : (a -> a -> Bool) -> List a -> List (Nonempty a)
groupWhile eq xs_ =
case xs_ of
[] ->
[]
x :: xs ->
let
(ys, zs) =
List.Extra.span (eq x) xs
in
(List.Nonempty.Nonempty x ys) :: groupWhile eq zs And now I can use It for sure is a tricky question. Maybe |
Well if the proposal to change the return type of
After thinking about it more, I'm beginning to think that this is the right way to go. |
Yeah? I still think we should move forward with this. In the PR, I recommended including helper functions for non-empty lists and then the topic shifted over to how much of a problem with out be to add helper functions and cohere other functions where this non-empty stuff is applicable. I dont think it will be that drastic of a change. As far as helpers go, we already have So my expectation (but maybe we should look more closely into this) is to make this change to using non-emptys, we just need maybe two helpers, and we have to make major changes to the other group while functions. That all seems worth it to me but Im open to different evaluations. |
I am in support of moving forward with the PR to make the group functions return I am still not sure about if the non-empty helper functions should (a) be in List-Extra, (b) be in a different package or module, or (c) not exist in an elm-community package altogether. If we are only planning on adding P.S. Small correction, the type of |
Okay, then how about we just change the type signature for Then we can also open up one or more issues to talk about helpers and how non-empty fits into |
I merged the PR for this, and opened up a discussion at issue #105 . Since this is over, I am closing this issue! 🎉 |
groupWhile : (a -> a -> Bool) -> List a -> List (List a)
Should be
groupWhile : (a -> a -> Bool) -> List a -> List (Nonempty a)
The issue is that Nonempty is a different package obviously. But as it stands it's kind of wrong, no? Maybe it belongs on the other package though.
The text was updated successfully, but these errors were encountered: