]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/sequences/lib/lib.factor
Fix conflict
[factor.git] / extra / sequences / lib / lib.factor
index a28fe32818384c0c4741a8e0572883a2bc415e4b..269c22e81138c908df03a9efc564781d5bd6a824 100755 (executable)
@@ -1,5 +1,6 @@
 USING: combinators.lib kernel sequences math namespaces assocs 
 random sequences.private shuffle math.functions mirrors ;
+USING: arrays math.parser sorting strings ;
 IN: sequences.lib
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -113,3 +114,20 @@ PRIVATE>
 
 : partition ( seq quot -- trueseq falseseq )
     over >r 2pusher >r >r each r> r> r> drop ; inline
+
+: cut-find ( seq pred -- before after )
+    dupd find drop dup [ cut ] when ;
+
+: cut3 ( seq pred -- first mid last )
+    [ cut-find ] keep [ not ] compose cut-find ;
+
+: (cut-all) ( seq pred quot -- )
+    [ >r cut3 r> dip >r >r , r> [ , ] when* r> ] 2keep
+    pick [ (cut-all) ] [ 3drop ] if ;
+
+: cut-all ( seq pred quot -- first mid last )
+    [ (cut-all) ] { } make ;
+
+: human-sort ( seq -- newseq )
+    [ dup [ digit? ] [ string>number ] cut-all ] { } map>assoc
+    sort-values keys ;