sequences.extras: Add set-nths and set-nths-unsafe for setting many indices in a sequence to the same value.

db4
Doug Coleman 2012-10-25 16:14:07 -07:00
parent b867a248a2
commit 01227b3331
2 changed files with 12 additions and 0 deletions

View File

@ -158,3 +158,9 @@ IN: sequences.extras.tests
{ "defg" } [ B{ 97 98 99 100 101 102 103 } 3 "" tail-as ] unit-test
{ "efg" } [ B{ 97 98 99 100 101 102 103 } 3 "" tail*-as ] unit-test
{ { 1 0 0 1 0 0 0 1 0 0 } }
[ 1 { 0 3 7 } 10 0 <array> [ set-nths ] keep ] unit-test
{ { 1 0 0 1 0 0 0 1 0 0 } }
[ 1 { 0 3 7 } 10 0 <array> [ set-nths-unsafe ] keep ] unit-test

View File

@ -356,3 +356,9 @@ PRIVATE>
[ length ] keep ensure swap pick (a,b]
over '[ [ 1 + ] keep _ move-unsafe ] each
set-nth-unsafe ;
: set-nths ( value indices seq -- )
swapd '[ [ _ ] dip _ set-nth ] each ; inline
: set-nths-unsafe ( value indices seq -- )
swapd '[ [ _ ] dip _ set-nth-unsafe ] each ; inline