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

Feature request: chunks #3

Closed
mcastorina opened this issue Jan 31, 2021 · 6 comments
Closed

Feature request: chunks #3

mcastorina opened this issue Jan 31, 2021 · 6 comments

Comments

@mcastorina
Copy link

First off, thanks for making this great library!

What do you think of adding a chunks(n) function that splits an Array into n-sized Arrays?

Something like..

>>> Array(range(10)).chunks(5)
Array(Array(0, 1, 2, 3, 4), Array(5, 6, 7, 8, 9))

I'd be happy to contribute this feature as well.

@mcastorina
Copy link
Author

It would be functionally the same as

arr.splitAt(range(n, arr.length, n))

@Lauriat
Copy link
Owner

Lauriat commented Jan 31, 2021

The same result can also be achieved with
arr.splitTo(arr.size // chunkSize)
but adding a chunks() may indeed be useful.
Thanks!

@mcastorina
Copy link
Author

I would prefer splitAt so n doesn't have to divide evenly into the size.

Also, let me know if you would like me to make a PR or not :)

@Lauriat
Copy link
Owner

Lauriat commented Jan 31, 2021

It's there now!

@mcastorina
Copy link
Author

Awesome!

Another good feature could be windows(n) where n is the window size.

>>> Array(range(6)).windows(3)
Array(Array(0, 1, 2), Array(1, 2, 3), Array(2, 3, 4), Array(3, 4, 5))

@Lauriat
Copy link
Owner

Lauriat commented Feb 3, 2021

Implemented - thanks for your suggestions!

@Lauriat Lauriat closed this as completed Feb 3, 2021
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