{ "cba" } [ "abcdef" 3 head-slice reverse ] unit-test
-{ 5040 } [ [ 1 2 3 4 5 6 7 ] 1 [ * ] reduce ] unit-test
+{ 5040 5040 } [
+ [ 1 2 3 4 5 6 7 ] dup rest-slice
+ [ 1 [ * ] reduce ] bi@
+] unit-test
+
+{ 10079 6459 } [
+ [ 1 2 3 4 5 6 7 ] dup rest-slice
+ [ 1 [ [ * ] [ + ] bi* ] reduce-index ] bi@
+] unit-test
{ 5040 { 1 1 2 6 24 120 720 } }
[ { 1 2 3 4 5 6 7 } 1 [ * ] accumulate ] unit-test
[ { CHAR: l CHAR: l } "o" { } 1surround-as ] unit-test
{ "ollo" }
-[ { CHAR: l CHAR: l } "o" "" 1surround-as ] unit-test
\ No newline at end of file
+[ { CHAR: l CHAR: l } "o" "" 1surround-as ] unit-test
: (each-from) ( seq quot i -- i n quot' )
[ (each) ] dip [ + ] curry 2dip ; inline
-: (each-index) ( seq quot -- i n quot' )
- [ setup-each [ keep ] curry ] dip compose ; inline
-
-: (each-index-from) ( seq quot i -- i n quot' )
- [ (each-index) ] dip [ + ] curry 2dip ; inline
-
: (collect) ( quot into -- quot' )
[ [ keep ] dip set-nth-unsafe ] 2curry ; inline
: collect ( n quot into -- )
(collect) each-integer ; inline
-: setup-map-each ( seq -- n quot )
+: setup-1each ( seq -- n quot )
[ length check-length ] keep [ nth-unsafe ] curry ; inline
-: (map-each) ( seq quot -- n quot' )
- [ setup-map-each ] dip compose ; inline
+: (1each) ( seq quot -- n quot' )
+ [ setup-1each ] dip compose ; inline
-: (map-each-index) ( seq quot -- n quot' )
- [ setup-map-each [ keep ] curry ] dip compose ; inline
+: (each-index) ( seq quot -- n quot' )
+ [ setup-1each [ keep ] curry ] dip compose ; inline
: map-into ( seq quot into -- )
- [ (map-each) ] dip collect ; inline
+ [ (1each) ] dip collect ; inline
: 2nth-unsafe ( n seq1 seq2 -- elt1 elt2 )
[ nth-unsafe ] bi-curry@ bi ; inline
over [ dupd nth-unsafe ] [ drop f ] if ; inline
: (find) ( seq quot quot' -- i elt )
- pick [ [ (map-each) ] dip call ] dip finish-find ; inline
+ pick [ [ (1each) ] dip call ] dip finish-find ; inline
: (find-from) ( n seq quot quot' -- i elt )
[ 2dup bounds-check? ] 2dip
- [ (find) ] 2curry
- [ 2drop f f ]
- if ; inline
+ '[ _ _ (find) ] [ 2drop f f ] if ; inline
: (find-index) ( seq quot quot' -- i elt )
- pick [ [ (map-each-index) ] dip call ] dip finish-find ; inline
+ pick [ [ (each-index) ] dip call ] dip finish-find ; inline
: (find-index-from) ( n seq quot quot' -- i elt )
[ 2dup bounds-check? ] 2dip
- [ (find-index) ] 2curry
- [ 2drop f f ]
- if ; inline
+ '[ _ _ (find-index) ] [ 2drop f f ] if ; inline
: (accumulate) ( seq identity quot -- identity seq quot )
swapd [ keepd ] curry ; inline
overd [ [ collect ] keep ] new-like ; inline
: map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
- [ (map-each) ] dip map-integers ; inline
+ [ (1each) ] dip map-integers ; inline
: map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
over map-as ; inline
[ dup ] swap [ keep ] curry produce nip ; inline
: each-index ( ... seq quot: ( ... elt index -- ... ) -- ... )
- (each-index) (each-integer) ; inline
+ (each-index) each-integer ; inline
: map-index-as ( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )
[ dup length <iota> ] 2dip 2map-as ; inline