[ { "foo" } ] [ { { "foo" } { "bar" } } [ first ] supremum-by ] unit-test
[ { "bar" } ] [ { { "foo" } { "bar" } } [ first ] infimum-by ] unit-test
+[ { 0 0 255 } ] [
+ {
+ { 0 0 0 }
+ { 95 255 95 }
+ { 215 95 95 }
+ { 95 135 255 }
+ { 135 95 135 }
+ { 135 255 255 }
+ { 0 0 255 }
+ { 0 95 95 }
+ { 0 255 215 }
+ { 135 0 95 }
+ { 255 0 175 }
+ } [ { 0 0 255 } distance ] infimum-by
+] unit-test
+
{ V{ 0 1 2 3 4 5 6 7 8 9 } } [
V{ } clone
10 iota >array randomize
: supremum-by ( seq quot: ( ... elt -- ... x ) -- elt )
[ [ first dup ] dip call ] 2keep [
dupd call pick dupd max over =
- [ [ 2drop ] 2dip ] [ 2nip ] if
+ [ [ 2drop ] 2dip ] [ 2drop ] if
] curry 1 each-from drop ; inline
: infimum-by ( seq quot: ( ... elt -- ... x ) -- elt )
[ [ first dup ] dip call ] 2keep [
dupd call pick dupd min over =
- [ [ 2drop ] 2dip ] [ 2nip ] if
+ [ [ 2drop ] 2dip ] [ 2drop ] if
] curry 1 each-from drop ; inline
: all-subseqs ( seq -- seqs )