filter

get collection's items by filtering those that do not fulfil given condition


Parameters

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

Attributes

with:literaluse given index
first:integeronly filter first element/s
last:integeronly filter last element/s

Returns

  • :block
  • or  :nothing
  • :any

Examples

copy
print filter 1..10 [x][ even? x ] ; 1 3 5 7 9

copy
arr: 1..10 filter 'arr 'x -> even? x print arr ; 1 3 5 7 9

copy
filter [1 1 2 3 5 8 13 21] [x y]-> odd? x+y ; => [1 1 13 21]

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

copy
filter.first 1..10 => odd? => [2 3 4 5 6 7 8 9 10] filter.first:3 1..10 => odd? => [2 4 6 7 8 9 10]

copy
filter.last 1..10 => odd? => [1 2 3 4 5 6 7 8 10] filter.last:3 1..10 => odd? => [1 2 3 4 6 8 10]

Related