Add indices word
parent
d5140cf248
commit
996dd6442e
|
@ -265,4 +265,6 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
|
|||
|
||||
[ { 1 3 7 } ] [ 2 { 1 3 5 7 } remove-nth ] unit-test
|
||||
|
||||
[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ] unit-test
|
||||
[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ]
|
||||
|
||||
[ V{ 0 2 } ] [ "a" { "a" "b" "a" } indices ] unit-test
|
||||
|
|
|
@ -480,6 +480,11 @@ PRIVATE>
|
|||
: last-index-from ( obj i seq -- n )
|
||||
rot [ = ] curry find-last-from drop ;
|
||||
|
||||
: indices ( obj seq -- indices )
|
||||
V{ } clone spin
|
||||
[ rot = [ over push ] [ drop ] if ]
|
||||
curry each-index ;
|
||||
|
||||
: nths ( seq indices -- seq' )
|
||||
swap [ nth ] curry map ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue