factor/contrib/sequences.factor

20 lines
563 B
Factor

USING: kernel math sequences ;
IN: sequences-contrib
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: 3nth ( n seq -- slice ) >r dup 3 + r> <slice> ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: map3-i ( seq -- i ) length 2 - ;
: map3-quot ( quot -- quot ) [ swap 3nth ] swap append ;
: map3 ( seq quot -- seq ) over map3-i swap map3-quot map-with ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: last ( seq -- elt ) dup length 1- swap nth ;
PROVIDE: contrib/sequences ;