View source: R/20-api-generics.R
| split_around_by_predicate | R Documentation |
Splits at the first point where a predicate function becomes TRUE
while scanning the sequence.
split_around_by_predicate(t, predicate, monoid_name, accumulator = NULL)
t |
A |
predicate |
Function applied to accumulated monoid values. |
monoid_name |
Name of the monoid used for scanning. |
accumulator |
Optional starting accumulator value. |
This function generally requires the sequence be annotated with
a measure_monoid(); see the examples and measure_monoid()
for more information.
value is the matched leaf entry for the input structure:
flexseq: stored user element.
ordered_sequence: list(value, key).
priority_queue: list(value, priority).
interval_index: list(value, start, end).
left and right preserve subclass when the input is a subclass of
flexseq.
A list with fields:
left: elements before the split point.
value: the matched element at the split point.
right: elements after the split point.
x <- flexseq("a", "b", "c", "d")
# Each element e has measure 1; the accumulated measure for
# a set of elements is computed by the associative function `+`
# along with the identity value 0.
size_monoid <- measure_monoid(`+`, 0L, function(e) 1L)
x2 <- add_monoids(x, list(size = size_monoid))
# the first time the measure stored in the size monoid
# accumulates to greater than or equal to 3 is the 3rd
# element in sequence.
split_around_by_predicate(x2, function(v) v >= 3L, "size")
# Split at the first element
split_around_by_predicate(x2, function(v) v >= 1L, "size")
# Split at the last element
split_around_by_predicate(x2, function(v) v >= 4L, "size")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.