sequences.extras: Add set-nths and set-nths-unsafe for setting many indices in a sequence to the same value.
parent
b867a248a2
commit
01227b3331
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue