{ 2 7 1 8 1 7 1 8 2 8 4 } [ ] occurrence-count-by
] unit-test
+{ { 1 2 0 3 3 3 3 3 3 3 3 3 3 3 3 3 } } [
+ "cab" "abcdefghijklmnop" progressive-index nip
+] unit-test
+
+{ { 0 1 2 3 3 } } [
+ "aaa" "aaaaa" progressive-index nip
+] unit-test
+
+{ { 0 3 1 4 2 5 5 5 5 5 } } [
+ "aaabb" "ababababab" progressive-index nip
+] unit-test
+
{ { 0 1 2 3 } } [ 8 <iota> [ 4 < ] take-while >array ] unit-test
{ { } } [ { 15 16 } [ 4 < ] take-while >array ] unit-test
{ { 0 1 2 } } [ 3 <iota> [ 4 < ] take-while >array ] unit-test
: 0accumulate ( ... seq quot: ( ... prev elt -- ... next ) -- ... final newseq )
over 0accumulate-as ; inline
-: occurrence-count-by ( seq quot: ( elt -- elt' ) -- hash seq )
+: occurrence-count-by ( seq quot: ( elt -- elt' ) -- hash seq' )
'[ nip @ over inc-at* ] H{ } clone -rot 0accumulate ; inline
-: occurrence-count ( seq -- hash seq )
+: occurrence-count ( seq -- hash seq' )
[ ] occurrence-count-by ; inline
+: nth-index ( n obj seq -- i )
+ [ = dup [ drop 1 - dup 0 < ] when ] with find drop nip ;
+
+: progressive-index-by-as ( seq1 seq2 quot exemplar -- hash seq' )
+ [
+ pick length '[
+ tuck [ @ over inc-at* ] 2dip swap nth-index _ or
+ ] [ H{ } clone ] 3dip with
+ ] dip map-as ; inline
+
+: progressive-index-by ( seq1 seq2 quot -- hash seq' )
+ { } progressive-index-by-as ; inline
+
+: progressive-index ( seq1 seq2 -- hash seq' )
+ [ ] progressive-index-by ; inline
+
: 0reduce ( seq quot: ( prev elt -- next ) -- result )
[ 0 ] dip reduce ; inline
over [ seq>> nth-unsafe ] [ 2array ] bi* ; inline
INSTANCE: virtual-zip-index immutable-sequence
-
-: nth-index ( n obj seq -- i )
- [ = dup [ drop 1 - dup 0 < ] when ] with find drop nip ;