Add map-until and a unit test for it
parent
8fadc570fc
commit
db3fbb52b2
|
@ -39,3 +39,5 @@ math.functions tools.test ;
|
|||
|
||||
[ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test
|
||||
[ V{ } [ delete-random drop ] keep length ] unit-test-fails
|
||||
|
||||
[ { 1 9 25 } ] [ { 1 3 5 6 } [ sq ] [ even? ] map-until ] unit-test
|
||||
|
|
|
@ -62,3 +62,11 @@ IN: sequences.lib
|
|||
|
||||
: delete-random ( seq -- value )
|
||||
[ length random ] keep [ nth ] 2keep delete-nth ;
|
||||
|
||||
: (map-until) ( quot pred -- )
|
||||
[ dup ] swap 3compose
|
||||
[ [ drop t ] [ , f ] if ] compose [ find 2drop ] curry ;
|
||||
|
||||
: map-until ( seq quot pred -- )
|
||||
#! Example: { 1 3 5 6 } [ sq ] [ even? ] map-until . -> { 1 9 25 }
|
||||
(map-until) { } make ;
|
||||
|
|
Loading…
Reference in New Issue