-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Make Relude.List.permutations
return a NonEmpty
.
#385
Comments
Do people actually use the standard |
I do. Why not? Maybe I am not aware of alternatives. |
Okay, I see that this function is used quite often in different packages. In that case, making its return type consistent with actual behaviour. I'm surprised the I encourage you (or anyone else) to open a proposal to But for now, we can implement a safer version in |
I was thinking about this issue for a while and I think that the best way to resolve this problem is to provide a separate function that works for permutations :: NonEmpty a -> NonEmpty (NonEmpty a) Implementation of this function is probably slightly more complicated that the existing However, I'd love to have this function implemented in One of the Once the CLC proposal is accepted and the new type-safe
|
I do not see why this function should not accept an empty list as an input. As I see it, we should require as few assumptions as we can. We do not need the assumption that the input is non-empty, so we should not require it. |
You may observe that any list has at least one permutation. The empty list's only permutation is the empty list itself, so:
This behaviour is also theoretically sound since permutations of a list are a model of a symmetric group and a group always has at least one element.
It is nicer to have to drop from a
NonEmpty
to a list than to lift from a list toNonEmpty
, since the latter requires the handling of the spurious case of the list being empty.The text was updated successfully, but these errors were encountered: