]> gitweb.factorcode.org Git - factor.git/commitdiff
monotonic-split works on empty seqs
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 28 Jun 2008 00:40:46 +0000 (19:40 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 28 Jun 2008 00:40:46 +0000 (19:40 -0500)
extra/sequences/lib/lib.factor

index 56488818ab2a856625e91b9daba7b46086c88bdf..324b8d166d40beb295c31e12f3cc1ad53be3d71f 100755 (executable)
@@ -106,17 +106,21 @@ MACRO: firstn ( n -- )
 : v, ( -- ) V{ } clone , ;
 : ,v ( -- ) building get dup peek empty? [ dup pop* ] when drop ;
 
-: monotonic-split ( seq quot -- newseq )
+: (monotonic-split) ( seq quot -- newseq )
     [
         >r dup unclip suffix r>
         v, [ pick ,, call [ v, ] unless ] curry 2each ,v
     ] { } make ;
 
+: monotonic-split ( seq quot -- newseq )
+    over empty? [ 2drop { } ] [ (monotonic-split) ] if ;
+
 : delete-random ( seq -- value )
     [ length random ] keep [ nth ] 2keep delete-nth ;
 
+ERROR: element-not-found ;
 : split-around ( seq quot -- before elem after )
-    dupd find over [ "Element not found" throw ] unless
+    dupd find over [ element-not-found ] unless
     >r cut rest r> swap ; inline
 
 : (map-until) ( quot pred -- quot )