2009-06-25 17:09:23 -04:00
|
|
|
USING: arrays kernel locals math sequences ;
|
|
|
|
IN: sequences.extras
|
|
|
|
: reduce1 ( seq quot -- result ) [ unclip ] dip reduce ; inline
|
|
|
|
|
|
|
|
:: reduce-r
|
|
|
|
( list identity quot: ( obj1 obj2 -- obj ) -- result )
|
|
|
|
list empty?
|
|
|
|
[ identity ]
|
|
|
|
[ list rest identity quot reduce-r list first quot call ] if ;
|
|
|
|
inline recursive
|
|
|
|
|
|
|
|
! Quot must have static stack effect, unlike "reduce"
|
|
|
|
:: reduce* ( seq id quot -- result ) seq
|
|
|
|
[ id ]
|
|
|
|
[ unclip id swap quot call( prev elt -- next ) quot reduce* ] if-empty ; inline recursive
|
|
|
|
|
|
|
|
:: combos ( list1 list2 -- result ) list2 [ [ 2array ] curry list1 swap map ] map concat ;
|
|
|
|
: find-all ( seq quot -- elts ) [ [ length iota ] keep ] dip
|
2009-08-04 18:16:34 -04:00
|
|
|
[ dupd call( a -- ? ) [ 2array ] [ 2drop f ] if ] curry 2map [ ] filter ; inline
|