-
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
Add sliding function #87
base: master
Are you sure you want to change the base?
Conversation
@@ -1218,7 +1255,7 @@ The equality test should be an [equivalence relation](https://en.wikipedia.org/w | |||
- Symmetry - Testing two objects should give the same result regardless of the order they are passed. | |||
- Transitivity - If the test on a first object and a second object results in `True`, and further if the test on that second object and a third also results in `True`, then the test should result in `True` when the first and third objects are passed. | |||
|
|||
For non-equivalent relations `groupWhile` has non-intuitive behavior. For example, inequality comparisons like `(<)` are not equivalence relations, so do _not_ write `groupWhile (<) [1,3,5,2,4]`, as it will give an unexpected answer. | |||
For non-equivalent relations `groupWhile` has non-intuitive behavior. For example, inequality comparisons like `(<)` are not equivalence relations, so do *not* write `groupWhile (<) [1,3,5,2,4]`, as it will give an unexpected answer. |
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 think elm format did this. Do you need it to be reverted?
Looks very similar (if not identical) to P.S. Either way, I like your name better and I'm in favor of renaming the |
I think you are right! It is already in the library, i overlooked for it. Then this PR wont be needed. Cheers! |
I wrote sliding in elm to have the same behavior as sliding in scala. Guess you can argue for both, while i favor sliding because you do not end up with smaller groups if you already used those numbers in previous groups. I made a little demo on ellie to demonstrate the differences. Please let me know your thoughts on this one |
Ah, so it's what is currently called Perhaps that section of the docs could use a little overview of what the differences between all these functions are. Worse, the docs for All that leads me to believe that this section has bad docs: in order to know which of the 5 grouping functions you need, you need to read the docs for all 5 of them, and compare their behaviour in your head and think "does this match my problem". While reading every section, one also needs to side-scroll the examples because only the input shows up, so by the time I can actually see the output, the input is scrolled away. It's easier said than done, but I think the docs in that section could use some love. |
@zwilias i tested I do agree with the naming/docs issue. But if you have a lot of grouping functions then i will get hard to name them in a way that most people understand or recognize. |
Sure. Since the point of this package is to provide a whole bunch of functions for convenience, and I'm sure someone has had a use for every one of those grouping functions, I think finding better names isn't quite as important here as providing very very clear docs. Split to groups of given sizeThere is bunch of ways of splitting a list into sublists, so we have different functions for different use-cases. Slicing and successive groupsThere are 3 ways to do this.
Grouping with more control and sliding windows
If each of those functions has a very short and quick recap of its own behaviour, and a couple of short examples with some whitespace for readability, I think this could actually be a pretty manageable section. My descriptions above are too long, but for a first draft, that's okay. We could even have some gifs/visualizations; helping folks see what a function does would be really helpful. |
Actually, |
@pzp1997 You are right. I checked with scala sliding again and it looks like this elm sliding is behaving the same as scala: What slidings intention looks like is that it need to cover all values. And it stops when the last value is used. But greedyGroupsOfWithStep 2 1 [1, 2, 3, 4, 5] == [[1,2],[2,3],[3,4],[4,5],[5]]
sliding 2 1 [1, 2, 3, 4, 5] == [[1,2],[2,3],[3,4],[4,5]] Sliding uses all values even if it can not fill a group. While groupsOfWithStep 3 3 [1, 2, 3, 4, 5] == [[1,2,3]]
sliding 3 3 [1, 2, 3, 4, 5] == [[1,2,3],[4,5]] |
Since they are so similar, should we even include this new |
I am in need of this behavior and because it is also exists in another language natively hereby the proposal. |
In my eyes, the problem is that there are too many possible variants of sliding functions to include them all in the library. (And, unfortunately, I'm not sure which ones are actually useful.) What is your use case that requires this exact variant? Why does the existing |
Hello,
I added the
sliding
function like the one in scala listSliding lets you group a list based on a sliding windows. You can set a size which is the group size. And a step which is how many steps you take for each group. I used this function in scala a lot and i now needed in in elm. So hereby my contribution.
Please let me know your thoughts and hopefully it will get accepted.
Cheers