diff --git a/extra/sequences/lib/lib-tests.factor b/extra/sequences/lib/lib-tests.factor index e457139bcd..470cd096e1 100644 --- a/extra/sequences/lib/lib-tests.factor +++ b/extra/sequences/lib/lib-tests.factor @@ -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 diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index 147af87cc2..d6cf1fe1dc 100644 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -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 = ; +