-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add FromList
#238
Add FromList
#238
Conversation
1aa90fd
to
d787df8
Compare
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.
The sad point here is that we cannot define it opposite to toList
because for e.g. Map our toList returns only values, unfortunatelly.
(Maybe this is worth changing one day?)
We have too many functions for conversion to lists, I mean toPairs
, keys
, elems
, so the situation with them already looks somewhat complicated to me and I think we need a really good reason to change toList
and this one is not sufficiently good. So I would personally just accept that fromList
is not always the opposite to toList
.
Another (potentially weird) idea that comes to my mind is to have no fromList
for maps and instead have fromPairs
in ToPairs
class 🤷 But fromList
is a standard name while fromPairs
is not, so it's probably not a good idea.
src/Universum/Container/Class.hs
Outdated
|
||
instance FromList [a] where | ||
instance FromList (Vector a) where | ||
instance FromList (Seq a) where |
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.
You wrote trailing where
for these 3 instances, but didn't write it for some instances below.
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.
🤦
CHANGES.md
Outdated
Unreleased | ||
===== | ||
|
||
* [#238](https://github.com/serokell/universum/issues/238): |
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.
Btw, the link refers to issues
, but 238 is this PR. Redirect works, but it looks weird :)
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.
Meh right, better be fixed
Thanks for your opinion here, I agree.
Probably this would make sense. I think However with this approach we get some redundancy, there will be two ways to do the same thing. But that is probably minor in this case. UPD: I wrote some nonsense initially, fixed now. |
Oops, I've pressed some wrong button |
0af7b88
to
2af9576
Compare
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'm fine with merging it in the current state.
Problem: we lack a generic function for constructing an object from list, while `toList` is present. Solution: add `fromList`. The sad point here is that we cannot define it opposite to `toList` because for e.g. `Map` our `toList` returns only values, unfortunatelly. (Maybe this is worth changing one day?) So `fromList` is opposite to something intermediate between `toList` and `toPairs`, and so I put it to a separate typeclass.
2af9576
to
9d2cb7f
Compare
We're now upgrading morley to LTS-19.3 and, as part of that, universum 1.7.3, which introduces I have a couple of questions:
|
In Moreover, if I need to have
I was also thinking about the ways to leave the instance but make it more safe, but didn't manage to come up with something worthy. Created #264 for this. |
I don't see how it would be weird, if both were exported from
I see your point, but I personally don't think that's enough to outweigh a bigger downside: the ecosystem has great support for A yet bigger problem is that the All in all, I don't think having to write one extra redundant line is worth these 2 downsides: instance IsList (MyList a) where
type Item (MyList a) = a
toList = Universum.toList -- <-- unfortunately redundant :/
fromList = myFromListImpl |
Maybe yes, but if we followed this reasoning, we wouldn't introduce Probably the scope of this issue is larger, and we should choose between
Oh, this is an issue I didn't fully accounted for. Somehow I supposed that another But nevertheless, the use of
By the way, considering your example, if we add a Also, thinking about it, maybe it's worth considering changing the name of |
Description
Problem: we lack a generic function for constructing an object from
list, while
toList
is present.Solution: add
fromList
.The sad point here is that we cannot define it opposite to
toList
because for e.g.
Map
ourtoList
returns only values, unfortunatelly.(Maybe this is worth changing one day?)
So
fromList
is opposite to something intermediate betweentoList
andtoPairs
, and so I put it to a separate typeclass.Related issues(s)
✓ Checklist for your Pull Request
Ideally a PR has all of the checkmarks set.
If something in this list is irrelevant to your PR, you should still set this
checkmark indicating that you are sure it is dealt with (be that by irrelevance).
are inextricably linked. Otherwise I should open multiple PR's.
reference this issue. See also auto linking on
github.
Related changes (conditional)
Tests
silently reappearing again.
Documentation
I checked whether I should update the docs and did so if necessary:
Record your changes
and
Stylistic guide (mandatory)
My commit history is clean (only contains changes relating to my
issue/pull request and no reverted-my-earlier-commit changes) and commit
messages start with identifiers of related issues in square brackets.
Example:
[#42] Short commit description
If necessary both of these can be achieved even after the commits have been
made/pushed using rebase and squash.