<PRIVATE
-: (setup-each) ( seq -- n quot )
+: setup-each ( seq -- n quot )
[ length check-length ] keep [ nth-unsafe ] curry ; inline
-: setup-each ( seq quot -- n quot' )
- [ (setup-each) ] dip compose ; inline
+: (each) ( seq quot -- n quot' )
+ [ setup-each ] dip compose ; inline
: (each-index) ( seq quot -- n quot' )
- [ (setup-each) [ keep ] curry ] dip compose ; inline
+ [ setup-each [ keep ] curry ] dip compose ; inline
: (collect) ( quot into -- quot' )
[ [ keep ] dip set-nth-unsafe ] 2curry ; inline
(collect) each-integer ; inline
: map-into ( seq quot into -- )
- [ setup-each ] dip collect ; inline
+ [ (each) ] dip collect ; inline
: 2nth-unsafe ( n seq1 seq2 -- elt1 elt2 )
[ nth-unsafe ] bi-curry@ bi ; inline
: 3nth-unsafe ( n seq1 seq2 seq3 -- elt1 elt2 elt3 )
[ nth-unsafe ] tri-curry@ tri ; inline
+: setup-3each ( seq1 seq2 seq3 -- n quot )
+ [ [ length ] tri@ min min check-length ]
+ [ [ 3nth-unsafe ] 3curry ] 3bi ; inline
+
: (3each) ( seq1 seq2 seq3 quot -- n quot' )
- [
- [ [ length ] tri@ min min check-length ]
- [ [ 3nth-unsafe ] 3curry ] 3bi
- ] dip compose ; inline
+ [ setup-3each ] dip compose ; inline
: finish-find ( i seq -- i elt )
over [ dupd nth-unsafe ] [ drop f ] if ; inline
: (find) ( seq quot quot' -- i elt )
- pick [ [ setup-each ] dip call ] dip finish-find ; inline
+ pick [ [ (each) ] dip call ] dip finish-find ; inline
: (find-from) ( n seq quot quot' -- i elt )
[ 2dup bounds-check? ] 2dip
PRIVATE>
: each ( ... seq quot: ( ... x -- ... ) -- ... )
- setup-each each-integer ; inline
+ (each) each-integer ; inline
: each-from ( ... seq quot: ( ... x -- ... ) i -- ... )
- -rot setup-each (each-integer) ; inline
+ -rot (each) (each-integer) ; inline
: reduce ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... result )
swapd each ; inline
[ over ] dip [ [ collect ] keep ] new-like ; inline
: map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
- [ setup-each ] dip map-integers ; inline
+ [ (each) ] dip map-integers ; inline
: map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
over map-as ; inline
[ find-integer ] (find-index) ; inline
: all? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
- setup-each all-integers? ; inline
+ (each) all-integers? ; inline
: push-if ( ..a elt quot: ( ..a elt -- ..b ? ) accum -- ..b )
[ keep ] dip rot [ push ] [ 2drop ] if ; inline
: generic-flip ( matrix -- newmatrix )
[
[ first-unsafe length 1 ] keep
- [ length min ] setup-each (each-integer) <iota>
+ [ length min ] (each) (each-integer) <iota>
] keep
[ [ nth-unsafe ] with { } map-as ] curry { } map-as ; inline
{ array } declare
[
[ first-unsafe array-length 1 ] keep
- [ array-length min ] setup-each (each-integer) <iota>
+ [ array-length min ] (each) (each-integer) <iota>
] keep
[ [ { array } declare array-nth ] with { } map-as ] curry { } map-as ;