1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: make namespaces sequences kernel fry ;
4 IN: splitting.monotonic
6 : ,, ( obj -- ) building get peek push ;
7 : v, ( -- ) V{ } clone , ;
8 : ,v ( -- ) building get dup peek empty? [ dup pop* ] when drop ;
10 : (monotonic-split) ( seq quot -- newseq )
12 [ dup unclip suffix ] dip
13 v, '[ over ,, @ [ v, ] unless ] 2each ,v
16 : monotonic-split ( seq quot -- newseq )
17 over empty? [ 2drop { } ] [ (monotonic-split) ] if ; inline