_map
Def
Partial map
Partial map
Creates a new Stream by applying a partial function to all elements of current Stream on which the function is defined.
(0 <>> 26).stream.collect{
case i if(i%2==0) => ('a' + i).toChar
}.tp
// Output
Stream(a, c, e, g, i, k, m, o, q, s, u, w, y)
Note:
- Source
- _map.scala
Heavy flat map
Heavy flat map
FLAT_MAP is functionally equivalent to flatMap, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.
- Source
- _map.scala
Flat map
Flat map
Creates a new Stream by applying given function to all elements of current Stream and concatenating the results
(1 <> 3).stream.flatMap(i => Stream(i, i*10, i*100)).tp
// Output
Stream(1, 10, 100, 2, 20, 200, 3, 30, 300)
- Source
- _map.scala
Converts a stream of streams into a flat stream
Converts a stream of streams into a flat stream
The operation will only compile if stream elements are streams or stream convertible entities, like Able.Stream, Iterable, Iterator, etc.
val vs: Stream[Stream[Char]] = Stream(
'a' <> 'd',
Pack('x', 'y', 'z'),
Vector('v', 'e', 'c', 't', 'o', 'r'))
vs.flatten.tp // Prints Stream(a, b, c, d, x, y, z, v, e, c, t, o, r)
- Source
- _map.scala
Simple map
Simple map
Creates a new Stream where each element is a result of applying given function to current Stream elements
(0 <>> 26).stream.map(i => ('a' + i).toChar).tp
// Output
Stream(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
- Source
- _map.scala
Heavy map
Heavy map
MAP is functionally equivalent to map, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.
- Source
- _map.scala
Heavy optional map
Heavy optional map
MAP_OPT is functionally equivalent to mapOpt, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.
- Source
- _map.scala
Conditional map
Conditional map
This is a synthetic oeration which is inlined as:
map(v => if(condition(v)) fun(v) else v)
In some cicumstances using "mapIf" does not make sense, in some it is really usefull.
- Source
- _map.scala
Optional map
Optional map
Creates a new Stream where each element is a result of applying given function to Stream elements. If the function returns void option, the element is dropped.
(1 <> 10).stream.mapOpt(i => if(i % 2 == 0) "Even_"+i else VOID).tp
// Output
Stream(Even_2, Even_4, Even_6, Even_8, Even_10)
Pattern matching can be used, but the last void case must always be provided explicitly:
(0 <>> 26).stream.mapOpt{
case i if(i % 2 == 0) => ('a' + i).toChar
case _ => VOID
}.tp
// Output
Stream(a, c, e, g, i, k, m, o, q, s, u, w, y)
Note:
- Source
- _map.scala