-
Notifications
You must be signed in to change notification settings - Fork 2
filter
TurtleKitty edited this page May 18, 2019
·
1 revision
Generic filter procedure. It is defined for lists, vectors, tables, and sets.
(def xs '(foo 2 bar 3 baz 5))
(filter num? xs) ; (2 3 5)
(filter symbol? xs) ; (foo bar baz)
(def v #(vector foo 2 bar 3 baz 5))
(filter num? v) ; #(vector 2 3 5)
(filter symbol? v) ; #(vector foo bar baz)
(def s #(set foo 2 bar 3 baz 5))
(filter num? s) ; #(set 5 2 3)
(filter symbol? s) ; #(set bar baz foo)
(def t (: foo 2 bar 3 baz 5))
(filter (lambda (p) (= p.head 'foo)) t)
; #(table foo 2)
(filter (lambda (p) (= p.tail 5)) t)
; #(table baz 5)