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

Add transform operators #8

Open
andres-kovalev opened this issue Mar 24, 2020 · 0 comments
Open

Add transform operators #8

andres-kovalev opened this issue Mar 24, 2020 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@andres-kovalev
Copy link
Owner

buffer(size, stream) creates new stream where all source items grouped into sub groups

buffer(2, [1,2,3,4,5,6]) => [[1,2], [3,4], [5,6]]
buffer(3, [1,2,3,4,5,6]) => [[1,2,3], [4,5,6]]

bufferBy(predicate, stream) similar to previous one, but groups by predicate result

bufferBy(i => i%2===1, [1,2,3,4,5,6]) => [[1],[2],[3],[4],[5],[6]]
bufferBy(i < 3, [1,2,3,4,5,6]) => [[1,2],[3,4,5,6]]
bufferBy(i%3>0, [1,2,3,4,5,6]) => [[1,2],[3],[4,5],[6]]

pluck(field, stream) extracts field value from each item

pluck('a')
// equivalent to
map(({ a }) => a)

scan(accFn, stream) accumulates value of each item to produce new stream (like history of reduce() operation)

const add = (a,b) => a + b;
scan(add, [1,2,3,4,5,6]) => [1,3,6,10,15,21]

flatten(stream) flattens initial stream

flatten([[1,2,3],[4,5,6]]) => [1,2,3,4,5,6];
@andres-kovalev andres-kovalev added the enhancement New feature or request label Mar 24, 2020
@andres-kovalev andres-kovalev added this to the 1.1.0 milestone Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant