{ 328350 } [ 100 <iota> [ sq ] map-sum ] unit-test
-{ 50 } [ 100 <iota> [ even? ] count ] unit-test
-{ 50 } [ 100 <iota> [ odd? ] count ] unit-test
+{ 5 } [ { 1 f 3 f 5 f 7 f 9 f } count ] unit-test
+
+{ 50 } [ 100 <iota> [ even? ] count-by ] unit-test
+{ 50 } [ 100 <iota> [ odd? ] count-by ] unit-test
{ { "b" "d" } } [ { 1 3 } { "a" "b" "c" "d" } nths ] unit-test
{ { "a" "b" "c" "d" } } [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test
: subseq-unsafe ( from to seq -- subseq )
dup subseq-unsafe-as ; inline
+: seq-copy-loop ( dst dst-i src src-i src-stop -- dst )
+ 2dup >= [
+ 4drop
+ ] [
+ [
+ [ copy-nth-of-unsafe ] 4keep
+ [ 1 + ] 2dip 1 +
+ ] dip seq-copy-loop
+ ] if ; inline recursive
+
PRIVATE>
: subseq-as ( from to seq exemplar -- subseq )
: nths ( indices seq -- seq' )
[ [ nth ] curry ] keep map-as ;
+: nths-of ( seq indices -- seq' )
+ swap nths ; inline
+
: any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
find drop >boolean ; inline
: map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
[ 0 ] 2dip [ dip + ] with-assoc each ; inline
-: count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
- [ 1 0 ? ] compose map-sum ; inline
-
: count-by ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
[ 1 0 ? ] compose map-sum ; inline
+: count ( ... seq -- ... n )
+ [ ] count-by ; inline
+
: cartesian-each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )
[ with each ] 2curry each ; inline