A find
that will return the first value for which f
returns Some(...)
.
A find
that will return the first value for which f
returns Some(...)
.
This is an optimization over find
: it does not compute the found value f(r)
twice.
Type of the return value r
under Option
.
Mapping function.
Some(r)
if f
returned a non-empty option value; None
otherwise.
"flatMap + foldLeft" will perform a foldLeft
unless the function op
returns None
at some point in the sequence.
"flatMap + foldLeft" will perform a foldLeft
unless the function op
returns None
at some point in the sequence.
Type of the return value r
under Option
.
Initial value of type R
.
Binary operation, returning an Option[R]
.
Result value Some(r)
, having folded to the end of the sequence. Will return None
if op
returned None
at any point.
A standard Seq#groupBy
produces a Map
and loses the ordering present in the original sequence.
A standard Seq#groupBy
produces a Map
and loses the ordering present in the original sequence.
Instead, orderedMapGroupBy produces a sequence of tuples that preserves the ordering of the original sequence.
The result is not a true groupBy
since it never reorders sequence elements.
This is suitable for stream processing or for cases when the original sequence is sorted, and we need to split the sorted sequence into sorted subsequences.
For example, Seq(1,2,3,4).orderedMapGroupBy(x < 3)
yields Seq((true, Seq(1,2)), (false, Seq(3,4))
and Seq(1,2,3,2,1).orderedMapGroupBy(x < 3)
yields Seq((true, Seq(1,2)), (false, Seq(3)), (true, Seq(2,1)))
Type of the grouping key.
Type of the elements of the resulting sequence.
A function that determines the grouping key.
A function that is applied to elements as a map
.
Sequence of tuples similar to the output of groupBy
.