Cactoos flatMap类比
Cactoos flatMap analogy
有flatMap
analogy in Cactoos图书馆吗?我需要的正是 flatMap
所能提供的,但没有数据流:
The flatMap() operation has the effect of applying a one-to-many transformation to the elements of the stream, and then flattening the resulting elements into a new stream.
例如如果我在列表中有一些值,并且每个值都有子项目,并且我想从每个值中获取所有项目,我可以使用 flatMap
:
List<Value> values = someValues();
List<Item> items = values.stream()
.flatMap(val -> val.items().stream()) // val.items() returns List<Item>
.collect(Collectors.toList());
如何使用 Cactoos 而不是流来做同样的事情 API?
可以用Joined,相当于把一个Iterable
.
压平
例如,您可以这样写:
new Joined<>(new Mapped<>(val -> val.items(), someValues()));
有flatMap
analogy in Cactoos图书馆吗?我需要的正是 flatMap
所能提供的,但没有数据流:
The flatMap() operation has the effect of applying a one-to-many transformation to the elements of the stream, and then flattening the resulting elements into a new stream.
例如如果我在列表中有一些值,并且每个值都有子项目,并且我想从每个值中获取所有项目,我可以使用 flatMap
:
List<Value> values = someValues();
List<Item> items = values.stream()
.flatMap(val -> val.items().stream()) // val.items() returns List<Item>
.collect(Collectors.toList());
如何使用 Cactoos 而不是流来做同样的事情 API?
可以用Joined,相当于把一个Iterable
.
例如,您可以这样写:
new Joined<>(new Mapped<>(val -> val.items(), someValues()));