Split Around First Predicate Flip
Source:R/30-api-flexseq-split-tree.R
split_around_by_predicate.RdSplits a sequence into left context, matched element, and right context at the first point where `predicate` becomes `TRUE` on accumulated monoid measures.
Examples
x <- as_flexseq(letters[1:6])
x
#> FingerTree <size=6, named=no>
#> monoids: none
#>
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
#> [[3]]
#> [1] "c"
#>
#> [[4]]
#> [1] "d"
#>
#> [[5]]
#> [1] "e"
#>
#> [[6]]
#> [1] "f"
#>
s <- split_around_by_predicate(x, function(v) v >= 4, ".size")
s$elem
#> [1] "d"
s$left
#> FingerTree <size=3, named=no>
#> monoids: none
#>
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
#> [[3]]
#> [1] "c"
#>
s$right
#> FingerTree <size=2, named=no>
#> monoids: none
#>
#> [[1]]
#> [1] "e"
#>
#> [[2]]
#> [1] "f"
#>