]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: fix supremum-by and infimum-by to be row polymorphic.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 Apr 2013 18:10:01 +0000 (11:10 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 Apr 2013 18:10:01 +0000 (11:10 -0700)
core/sequences/sequences-tests.factor
core/sequences/sequences.factor

index 70bd01fb98f001ff6ce011feff4938aac3a41d81..cf41eb92222afd4281771514d835fec5b83dac03 100644 (file)
@@ -1,7 +1,7 @@
 USING: arrays byte-arrays kernel math math.order math.parser
 namespaces sequences kernel.private sequences.private strings
 sbufs tools.test vectors assocs generic vocabs.loader
-generic.single math.vectors ;
+generic.single math.vectors math.functions ;
 IN: sequences.tests
 
 [ "empty" ] [ { } [ "empty" ] [ "not empty" ] if-empty ] unit-test
@@ -359,6 +359,8 @@ USE: make
 { "bar" } [ { "bar" "baz" "qux" } [ length ] infimum-by ] unit-test
 [ { "foo" } ] [ { { "foo" } { "bar" } } [ first ] supremum-by ] unit-test
 [ { "bar" } ] [ { { "foo" } { "bar" } } [ first ] infimum-by ] unit-test
+{ -2 1 } [ -2 { 1 2 3 } [ over ^ ] supremum-by ] unit-test
+{ -2 3 } [ -2 { 1 2 3 } [ over ^ ] infimum-by ] unit-test
 
 [ { 0 0 255 } ] [
     {
index f209adfa6f4f6d15f1abc3df2d37699b7a984cfd..694c8c4754241e387239a42e07b3dd2c86139394 100644 (file)
@@ -1031,16 +1031,16 @@ M: object sum 0 [ + ] binary-reduce ; inline
 : each-from ( ... seq quot: ( ... x -- ... ) i -- ... )
     -rot (each) (each-integer) ; inline
 
-: supremum-by ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ [ first dup ] dip call ] 2keep [
-        dupd call pick dupd after?
-        [ [ 2drop ] 2dip ] [ 2drop ] if
+: supremum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
+    [ keep swap ] curry [ [ first ] dip call ] 2keep [
+        curry 2dip pick over after?
+        [ 2drop ] [ [ 2drop ] 2dip ] if
     ] curry 1 each-from drop ; inline
 
-: infimum-by ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ [ first dup ] dip call ] 2keep [
-        dupd call pick dupd before?
-        [ [ 2drop ] 2dip ] [ 2drop ] if
+: infimum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
+    [ keep swap ] curry [ [ first ] dip call ] 2keep [
+        curry 2dip pick over before?
+        [ 2drop ] [ [ 2drop ] 2dip ] if
     ] curry 1 each-from drop ; inline
 
 : shortest ( seqs -- elt ) [ length ] infimum-by ;