cluster

group together items in collection that abide by given predicate


Parameters

cluster collection :integer :string :literal :dictionary :object :inline :block :range
        params :null :literal :block
        condition :block :bytecode

Attributes

with :literal use given index
value also include condition values

Returns

  • :block
  • or  :nothing

Examples

copy
cluster 1..10 => odd? ; => [[1 3 5 7 9] [2 4 6 8 10]] cluster 1..10 'x -> prime? x ; => [[1 4 6 8 9 10] [2 3 5 7]]

copy
cluster 1..10 [x y] -> 10 < x+y ; => [[1 2 3 4] [5 6 7 8 9 10]]

copy
cluster.value 1..10 'x -> prime? x ; => [[false [1 4 6 8 9 10]] [true [2 3 5 7]]]

copy
#.raw flatten.once cluster.value 1..10 'x [ (prime? x)? -> "prime" -> "composite" ] ; => [composite:[1 4 6 8 9 10] prime:[2 3 5 7]]

copy
cluster.with: 'i ["one" "two" "three" "four" "five" "six"] [] -> even? i ; => [["one" "three" "five"] ["two" "four" "six"]]

Related