memo->clojure.contrib.seq-utils(1/2)
clojure-contrib-1.1.0のseq-utils一覧のメモ
flatten
入れ子になっているseq-able*1を平滑化
Plus it's lazy.との事
(flatten '[1 2 (3 [4] 5 "fred") [6 7]]) ;=> (1 2 3 4 5 "fred" 6 7)
separate,group-by,partition-by
述語の「真、偽」で分割
戻り値は、ベクタ、
戻り値は、true,falseのハッシュ、
戻り値は、連続して現れるリスト
(separate odd? [1,2,3,4,5,6,7]) ;=> [(1 3 5 7) (2 4 6)] (separate even? [1,2,3,4,5,6,7]) ;=> [(2 4 6) (1 3 5 7)] ;(filter (complement even?) [1,2,3,4,5,6,7]) ;=> (1 3 5 7) (group-by odd? [1,2,3,4,5,6,7]);=> {false [2 4 6], true [1 3 5 7]} (group-by even? [1,2,3,4,5,6,7]);=> {false [1 3 5 7], true [2 4 6]} (partition-by odd? [1,4,1,4,2,1,3,5,6]) ;=> ((1) (4) (1) (4 2) (1 3 5) (6)) (partition-by even? [1,7,3,2,0,5,0,8]) ;=> ((1 7 3) (2 0) (5) (0 8))
includes?
コレクションに値が、含むか?
(includes? '(:lisp,:python,:ruby) :lisp) ;=> true (includes? '(:lisp,:python,:ruby) :groovy) ;=> false
indexed
シーケンスにインデックスを振る
(indexed '(:a :b :c :d));=> ([0 :a] [1 :b] [2 :c] [3 :d])
frequencies
出現回数とのマップ
(frequencies [:a,:c,:a,:b,:a,:b]);=> {:b 2, :c 1, :a 3}