]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: faster minimum/maximum.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 16 Apr 2012 22:09:44 +0000 (15:09 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 16 Apr 2012 22:09:44 +0000 (15:09 -0700)
extra/sequences/extras/extras.factor

index 5189738fb78a54a9dc3e43cab1d21ca493e75d79..8cbe93e89ae9fb733cee8920410ba6a47b24f4cd 100644 (file)
@@ -30,12 +30,10 @@ IN: sequences.extras
     [ bi@ [ min ] keep eq? not ] curry most ; inline
 
 : maximum ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ keep 2array ] curry
-    [ [ first ] max-by ] map-reduce second ; inline
+    [ dup ?first ] dip [ max-by ] curry reduce ; inline
 
 : minimum ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ keep 2array ] curry
-    [ [ first ] min-by ] map-reduce second ; inline
+    [ dup ?first ] dip [ min-by ] curry reduce ; inline
 
 : all-subseqs ( seq -- seqs )
     dup length [1,b] [ <clumps> ] with map concat ;