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

Function to group by some property, and return tuples of the property and the sub-list #21

Closed
wmakley opened this issue Nov 16, 2016 · 2 comments

Comments

@wmakley
Copy link

wmakley commented Nov 16, 2016

Thanks for this library, I use it all the time! I forked it and am trying to add a function "groupBy" to transform a List where each element has some shared comparable property like this:

list : List (Int, String)
list =
    [ (1, "a"), (1, "b"), (2, "c") ]

{-| Output:
    [ (1, [ (1, "a"), (1, "b") ] )
    , (2, [ (2, "c") ] )
    ]
-}
grouped : List (Int, List (Int, String))
grouped =
    List.Extra.groupBy fst list

I am having trouble because I am still pretty slow at functional programming and it feels like solving an incredibly arduous math problem, so I figured I'd at least make an issue in case someone else with more experience can do it easily.

@jvoigtlaender
Copy link
Contributor

Seems you want http://package.elm-lang.org/packages/elm-community/dict-extra/1.3.1/Dict-Extra#groupBy. If you really want a list in the end, you can just follow up that function with a call to Dict.toList.

@wmakley
Copy link
Author

wmakley commented Nov 17, 2016

Perfect, thanks!

On Wed, Nov 16, 2016 at 12:50 PM Janis Voigtländer notifications@github.com
wrote:

Seems you want
http://package.elm-lang.org/packages/elm-community/dict-extra/1.3.1/Dict-Extra#groupBy.
If you really want a list in the end, you can just follow up that function
with a call to Dict.toList.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#21 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAfYjYVW6CNefHmRYJwGeXjEJbB_PluHks5q-0J3gaJpZM4K0MBy
.

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