]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: move min-by/max-by to math.compare.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 19 May 2012 18:26:01 +0000 (11:26 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 19 May 2012 18:26:01 +0000 (11:26 -0700)
extra/math/compare/compare-tests.factor
extra/math/compare/compare.factor
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index 5b30af0e63dd36de79d3e4502681d9144f6cf99a..cedea4984c4c34423349132e88fd7d4b21a7b945 100644 (file)
@@ -1,4 +1,6 @@
-USING: kernel math math.compare math.functions tools.test ;
+USING: kernel math math.compare math.functions sequences
+tools.test ;
+
 IN: math.compare.tests
 
 [ -1 ] [ -1 5 absmin ] unit-test
@@ -14,3 +16,14 @@ IN: math.compare.tests
 [ 0 ] [ 1 3 negmin ] unit-test
 [ -3 ] [ 1 -3 negmin ] unit-test
 [ -1 ] [ -1 3 negmin ] unit-test
+
+[ 1 ] [ 1 2 [ ] min-by ] unit-test
+[ 1 ] [ 2 1 [ ] min-by ] unit-test
+[ 42.0 ] [ 42.0 1/0. [ ] min-by ] unit-test
+[ 42.0 ] [ 1/0. 42.0 [ ] min-by ] unit-test
+[ 2 ] [ 1 2 [ ] max-by ] unit-test
+[ 2 ] [ 2 1 [ ] max-by ] unit-test
+[ 1/0. ] [ 42.0 1/0. [ ] max-by ] unit-test
+[ 1/0. ] [ 1/0. 42.0 [ ] max-by ] unit-test
+[ "12345" ] [ "123" "12345" [ length ] max-by ] unit-test
+[ "123" ] [ "123" "12345" [ length ] min-by ] unit-test
index f7f66da37ca88d49b5c441afb62b7bde5b5bc55d..08c25e4a34cf2de4815beb038c58a7a78224bbcc 100644 (file)
@@ -14,3 +14,11 @@ IN: math.compare
 
 : negmin ( a b -- x )
     0 min min ;
+
+: max-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
+    [ bi@ dupd max = ] curry most ; inline
+
+: min-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
+    [ bi@ dupd min = ] curry most ; inline
+
+
index 49b3a7e26d468f9d66a9b6433ed0de65015095d3..e33819e580018d800f57b4f968cedfdaf6c04c0a 100644 (file)
@@ -3,21 +3,10 @@ sequences.extras strings tools.test ;
 
 IN: sequences.extras.tests
 
-[ 1 ] [ 1 2 [ ] min-by ] unit-test
-[ 1 ] [ 2 1 [ ] min-by ] unit-test
-[ 42.0 ] [ 42.0 1/0. [ ] min-by ] unit-test
-[ 42.0 ] [ 1/0. 42.0 [ ] min-by ] unit-test
-[ 2 ] [ 1 2 [ ] max-by ] unit-test
-[ 2 ] [ 2 1 [ ] max-by ] unit-test
-[ 1/0. ] [ 42.0 1/0. [ ] max-by ] unit-test
-[ 1/0. ] [ 1/0. 42.0 [ ] max-by ] unit-test
-[ "12345" ] [ "123" "12345" [ length ] max-by ] unit-test
-[ "123" ] [ "123" "12345" [ length ] min-by ] unit-test
-
-[ 4 ] [ 5 iota [ ] maximum ] unit-test
-[ 0 ] [ 5 iota [ ] minimum ] unit-test
-[ { "foo" } ] [ { { "foo" } { "bar" } } [ first ] maximum ] unit-test
-[ { "bar" } ] [ { { "foo" } { "bar" } } [ first ] minimum ] unit-test
+[ 4 ] [ 5 iota [ ] supremum-by ] unit-test
+[ 0 ] [ 5 iota [ ] infimum-by ] unit-test
+[ { "foo" } ] [ { { "foo" } { "bar" } } [ first ] supremum-by ] unit-test
+[ { "bar" } ] [ { { "foo" } { "bar" } } [ first ] infimum-by ] unit-test
 
 { V{ 0 1 2 3 4 5 6 7 8 9 } } [
     V{ } clone
index 07ca0c3e22b528e1f0b753b1adc2f7d622c98e7c..b565894fc18f4fc0cc6efd1ad738c351294e7b16 100644 (file)
@@ -33,18 +33,6 @@ IN: sequences.extras
 : reduce-from ( ... seq identity quot: ( ... prev elt -- ... next ) i -- ... result )
     [ swap ] 2dip each-from ; inline
 
-: max-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
-    [ bi@ dupd max = ] curry most ; inline
-
-: min-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
-    [ bi@ dupd min = ] curry most ; inline
-
-: maximum ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ dup ?first ] dip [ max-by ] curry reduce ; inline
-
-: minimum ( seq quot: ( ... elt -- ... x ) -- elt )
-    [ dup ?first ] dip [ min-by ] curry reduce ; inline
-
 : supremum-by ( seq quot: ( ... elt -- ... x ) -- elt )
     [ [ first dup ] dip call ] 2keep [
         dupd call pick dupd max over =