-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement all the dict extra functions #7
Conversation
Wow, nice! @rgrempel is probably going to be happy :) |
Well, the missing quickchecks are a bit sad |
Are you already using it in a project, or just geeking out? |
I'm totally just geeking out, but I see it to be useful on my new project: a https://lobste.rs/ clone. I guess its also really related with your items and item managers work. |
The items manager is mostly about fetching and unwraping items from WebData, so when it hands it down to sub-components they get a non-wrapped Item (thus an easier one to interact with) |
@amitaibu The problem I tried to solve was a pager + updating the list of comments one wants to render. |
Then maybe you'd like to give this a stab? |
Interesting, thank you @amitaibu ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
src/DictList.elm
Outdated
-} | ||
|
||
import Dict exposing (Dict) | ||
import DictList.Compat exposing (customDecoder, decodeAndThen, first, maybeAndThen, second) | ||
import Json.Decode exposing (Decoder, keyValuePairs, value, decodeValue) | ||
import List.Extra | ||
import Set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May as well add exposing (Set)
, I think.
src/DictList.elm
Outdated
groupBy .id [mary, jack, jill] == DictList.fromList [(1, [mary, jill]), (2, [jack])] | ||
-} | ||
groupBy : (comparable1 -> a -> comparable2) -> DictList comparable1 a -> DictList comparable2 (List a) | ||
groupBy keyfn list = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think what we'd be looking for here is something like this instead:
groupBy : (a -> comparable) -> List a -> DictList comparable (List a)
That is, I think the input should still be a List
, not another DictList
. So, the signature would be the same except that we produce a DictList
instead of a Dict
. And, the additional behaviour would be that the resulting DictList
preserves the order of the incoming list (which Dict.Extra.groupBy
would not do).
Part of the logic is that we're in Dict.Extra
, so it is (generally speaking) the Dict
parameters that we want to be DictList
-- the List
things here really are meant to be good-old-lists (though there may be some exceptions).
Or, to put it another way, the point of groupBy
is to add keys to a list of values, so we need not require that we already have keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with you. Its not only that this is more parallel to DictExtra, but more important, this makes the function more useful for many usecases.
src/DictList.elm
Outdated
jill = {id=1, name="Jill"} | ||
fromListBy .id [mary, jack, jill] == DictList.fromList [(1, jack), (2, jill)] | ||
-} | ||
fromListBy : (comparable1 -> a -> comparable2) -> DictList comparable1 a -> DictList comparable2 a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above -- I think this makes more sense as really being a way to construct a DictList
from a List
, not from another DictList
. As written here, it's more of a variation on a map
... I suppose we could have another function and call it something like mapKeys
if it's useful. Ah, except that as I read on we already have a mapKeys
that just considers the key. I suppose we could have a mapKeysAndValues
, in theory -- I haven't really thought it through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, yeah I guess such a generic transformation function could be helpful, but indeed I think this doesn't have to be addressed as part of this PR.
@@ -0,0 +1,98 @@ | |||
module DictExtraTests exposing (tests) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good. I'd also suggest having a separate test file that copies https://github.com/elm-community/dict-extra/blob/1.3.2/tests/Main.elm and makes whatever the smallest changes are needed to match our context here. Basically, to prove that we pass Dict.Extra
's own tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done that.
I pushed some changes which should address all the points from you @rgrempel |
Are you sure you pushed the changes? I'm not seeing them ... |
Oops, this didn't went through the airport firewall.
Its on now. Sorry for the spam
Ryan Rempel <[email protected]> schrieb am Di., 28. März 2017 um
17:55 Uhr:
… Are you sure you pushed the changes? I'm not seeing them ...
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABz7nDGKH9S69fbQtvhzfVfQ4g4ykkWks5rqS1ngaJpZM4Mjb8i>
.
|
Thanks, this looks pretty good at first glance. I'll merge it as soon as I get a chance to review more carefully. |
Sorry this took 3 weeks for me to get back to -- looks good! |
Published as version 1.1 ... thanks again, @dawehner. |
This PR solves #3 aka. it implements all the methods from dict extra:
The test coverage for now is mostly unit test coverage as my knowledge of fuzz tests is still limited.