parent
7563e4b61e
commit
485d454f1d
extra/sequences/lib
|
@ -1,4 +1,5 @@
|
|||
USING: kernel sequences.lib math math.functions tools.test ;
|
||||
USING: arrays kernel sequences sequences.lib math
|
||||
math.functions tools.test ;
|
||||
|
||||
[ 4 ] [ { 1 2 } [ sq ] [ * ] map-reduce ] unit-test
|
||||
[ 36 ] [ { 2 3 } [ sq ] [ * ] map-reduce ] unit-test
|
||||
|
@ -28,3 +29,7 @@ USING: kernel sequences.lib math math.functions tools.test ;
|
|||
[ -11 -9 ] [ { -11 -10 -9 } minmax ] unit-test
|
||||
[ -1/0. 1/0. ] [ { -1/0. 1/0. -11 -10 -9 } minmax ] unit-test
|
||||
|
||||
[ { { 1 } { -1 5 } { 2 4 } } ]
|
||||
[ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test
|
||||
[ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ]
|
||||
[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: combinators.lib kernel sequences math
|
||||
USING: combinators.lib kernel sequences math namespaces
|
||||
sequences.private shuffle ;
|
||||
|
||||
IN: sequences.lib
|
||||
|
@ -46,3 +46,18 @@ IN: sequences.lib
|
|||
#! find the min and max of a seq in one pass
|
||||
1/0. -1/0. rot [ tuck max >r min r> ] each ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: ,, building get peek push ;
|
||||
: v, V{ } clone , ;
|
||||
: ,v building get dup peek empty? [ dup pop* ] when drop ;
|
||||
|
||||
: monotonic-split ( seq quot -- newseq )
|
||||
[
|
||||
>r dup unclip add r>
|
||||
v, [ pick ,, call [ v, ] unless ] curry 2each ,v
|
||||
] { } make ;
|
||||
|
||||
: singleton? ( seq -- ? )
|
||||
length 1 = ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue