In functional programming in Java or JavaScript libraries we have streams or some fp library similar to this:
new Stream([1, 2, 3]).map(x => x + 2).sort((a, b) => a-b).value();
This is Javascript sample but ignore the syntax for a moment.
I want to know is there way to pass multiple values along the stream.
For example:
I have array with authors, pictures and maybe some other variables.
The problem is that in this case I have to pass everything as object like this:
new Stream({authors: [1,2,3], pictures: ['a',...], config)
.filter({authors} => author > 1)
.map(obj => ...)
.sortBy((a, b) => a)
.value()
So the problem is that when I want to filter and map, sometimes I want the old values, or not filtered one.
If I have authors = [1,2, 3,4, 5]
Then I filter authors = [1,2,3]
If I have for example another map that I need to use old authors
, how to solve the issue.
Is there any standard ?
I can pass all data in one object but if I change some method between I have to change all chaining methods after it.
In this case if i change what .map()
is returning I will have to change sortBy
and so on.
Comments
Post a Comment