chunk

chunk together consecutive items in collection that abide by given predicate


Parameters

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

Attributes

with :literal use given index
value :any also include condition values

Returns

  • :block
  • or  :nothing

Examples

copy
chunk [1 1 2 2 3 22 3 5 5 7 9 2 5] => even? ; => [[1 1] [2 2] [3] [22] [3 5 5 7 9] [2] [5]]

copy
chunk.value [1 1 2 2 3 22 3 5 5 7 9 2 5] 'x [ odd? x ] ; => [[true [1 1]] [false [2 2]] [true [3]] [false [22]] [true [3 5 5 7 9]] [false [2]] [true [5]]]

copy
chunk.with:'i ["one" "two" "three" "four" "five" "six"] [] -> i < 4 ; => [["one" "two" "three" "four"] ["five" "six"]]

copy
chunk [1 7 5 4 3 6 8 2] [x y]-> even? x+y ; => [[1 7] [5 4 3 6] [8 2]]

Related