The main trait used to define pattern elements.
A lot of operations on Pat
are defined separately in PatOps
.
- See also
- Companion
- object
Value members
Abstract methods
Concrete methods
"Taps" into this pattern by appending a side-effect. The returned
pattern will invoke both the input stream and the stream
produced from the side-effecting pattern produced by f
,
and then pass through the input stream's value.
The side-effecting stream may end early, the compound stream keeps
producing while the input stream has elements.
"Taps" into this pattern by appending a side-effect. The returned
pattern will invoke both the input stream and the stream
produced from the side-effecting pattern produced by f
,
and then pass through the input stream's value.
The side-effecting stream may end early, the compound stream keeps
producing while the input stream has elements.
Similar to runWith
for standard Scala collections.
Wraps each element in a singleton pattern. For example,
Pat(1, 2, 3)
becomes Pat(Pat(1), Pat(2), Pat(3))
.
Wraps each element in a singleton pattern. For example,
Pat(1, 2, 3)
becomes Pat(Pat(1), Pat(2), Pat(3))
.
Chooses a random single element from the input pattern.
Chooses a random single element from the input pattern.
Drops the first length
elements of the input pattern.
If the length is greater than the input pattern length, the
result will be empty.
Drops the first length
elements of the input pattern.
If the length is greater than the input pattern length, the
result will be empty.
E.g. Pat(4, 5, 6).drop(2) == Pat(6)
Similar to a monadic flatMap
but with the constraint
the element type must be a (nested) pattern.
Similar to a monadic flatMap
but with the constraint
the element type must be a (nested) pattern.
Finds first index where this pattern contains a given other pattern as a slice.
Finds first index where this pattern contains a given other pattern as a slice.
- Value Params
- that
the sequence to test
- Returns
the first index such that the elements of this pattern starting at this index match the elements of pattern
that
, or-1
of no such subsequence exists.
Finds first index after or at a start index where this pattern contains a given other pattern as a slice.
Finds first index after or at a start index where this pattern contains a given other pattern as a slice.
- Value Params
- from
the start index
- that
the sequence to test
- Returns
the first index
>= from
such that the elements of this pattern starting at this index match the elements of patternthat
, or-1
of no such subsequence exists.
Yields the number of elements in the input pattern.
Yields the number of elements in the input pattern.
E.g. Pat(4, 5, 6).length == Pat(3)
Similar to a monadic map
but with the constraint
the element type must be a (nested) pattern.
Similar to a monadic map
but with the constraint
the element type must be a (nested) pattern.
Randomly changes the positions of the elements in the input pattern. Warning: the input must be finite.
Randomly changes the positions of the elements in the input pattern. Warning: the input must be finite.
Shorthand for calling both take
and drop
.
Shorthand for calling both take
and drop
.
Drops the first element of the pattern.
Drops the first element of the pattern.
E.g. Pat(4, 5, 6).tail == Pat(5, 6)
.
Takes only the length
first elements of the input pattern,
or less if the input pattern is shorter.
Takes only the length
first elements of the input pattern,
or less if the input pattern is shorter.
E.g. Pat(4, 5, 6).take(2) == Pat(4, 5)
Updates a single element. In other words, only one element from
index
and elem
is ever read.
Updates a single element. In other words, only one element from
index
and elem
is ever read.
E.g. Pat(4, 5, 6).updated(2, 7) == Pat(4, 5, 7)
Zips the indices with the elements, and then replaces these pairs. Eagerly expands the entire input pattern.
Zips the indices with the elements, and then replaces these pairs. Eagerly expands the entire input pattern.
Be careful that this hang if both index
and elem
are constants!