@@ -766,18 +766,12 @@ minimum(a; kw...) = mapreduce(identity, min, a; kw...)
766766
767767"""
768768 findmax(f, domain) -> (f(x), x)
769- findmax(f)
770769
771770Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
772771value in the `domain` (inputs to `f`) such that `f(x)` is maximised. If there
773772are multiple maximal points, then the first one will be returned.
774773
775- When `domain` is provided it may be any iterable and must not be empty.
776-
777- When `domain` is omitted, `f` must have an implicit domain. In particular, if
778- `f` is an indexable collection, it is interpreted as a function mapping keys
779- (domain) to values (codomain), i.e. `findmax(itr)` returns the maximal element
780- of the collection `itr` and its index.
774+ `domain` must be a non-empty iterable.
781775
782776Values are compared with `isless`.
783777
@@ -795,7 +789,21 @@ julia> findmax(first, [(1, :a), (2, :b), (2, :c)])
795789
796790julia> findmax(cos, 0:π/2:2π)
797791(1.0, 0.0)
792+ ```
793+ """
794+ findmax (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmax, domain)
795+ _rf_findmax ((fm, m), (fx, x)) = isless (fm, fx) ? (fx, x) : (fm, m)
796+
797+ """
798+ findmax(itr) -> (x, index)
798799
800+ Return the maximal element of the collection `itr` and its index or key.
801+ If there are multiple maximal elements, then the first one will be returned.
802+ Values are compared with `isless`.
803+
804+ # Examples
805+
806+ ```jldoctest
799807julia> findmax([8, 0.1, -9, pi])
800808(8.0, 1)
801809
@@ -805,28 +813,18 @@ julia> findmax([1, 7, 7, 6])
805813julia> findmax([1, 7, 7, NaN])
806814(NaN, 4)
807815```
808-
809816"""
810- findmax (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmax, domain)
811- _rf_findmax ((fm, m), (fx, x)) = isless (fm, fx) ? (fx, x) : (fm, m)
812-
813- findmax (a) = _findmax (a, :)
817+ findmax (itr) = _findmax (itr, :)
814818_findmax (a, :: Colon ) = mapfoldl ( ((k, v),) -> (v, k), _rf_findmax, pairs (a) )
815819
816820"""
817821 findmin(f, domain) -> (f(x), x)
818- findmin(f)
819822
820823Returns a pair of a value in the codomain (outputs of `f`) and the corresponding
821824value in the `domain` (inputs to `f`) such that `f(x)` is minimised. If there
822825are multiple minimal points, then the first one will be returned.
823826
824- When `domain` is provided it may be any iterable and must not be empty.
825-
826- When `domain` is omitted, `f` must have an implicit domain. In particular, if
827- `f` is an indexable collection, it is interpreted as a function mapping keys
828- (domain) to values (codomain), i.e. `findmin(itr)` returns the minimal element
829- of the collection `itr` and its index.
827+ `domain` must be a non-empty iterable.
830828
831829`NaN` is treated as less than all other values except `missing`.
832830
@@ -844,7 +842,22 @@ julia> findmin(first, [(1, :a), (1, :b), (2, :c)])
844842
845843julia> findmin(cos, 0:π/2:2π)
846844(-1.0, 3.141592653589793)
845+ ```
846+
847+ """
848+ findmin (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmin, domain)
849+ _rf_findmin ((fm, m), (fx, x)) = isgreater (fm, fx) ? (fx, x) : (fm, m)
847850
851+ """
852+ findmin(itr) -> (x, index)
853+
854+ Return the minimal element of the collection `itr` and its index or key.
855+ If there are multiple minimal elements, then the first one will be returned.
856+ `NaN` is treated as less than all other values except `missing`.
857+
858+ # Examples
859+
860+ ```jldoctest
848861julia> findmin([8, 0.1, -9, pi])
849862(-9.0, 3)
850863
@@ -854,27 +867,17 @@ julia> findmin([1, 7, 7, 6])
854867julia> findmin([1, 7, 7, NaN])
855868(NaN, 4)
856869```
857-
858870"""
859- findmin (f, domain) = mapfoldl (x -> (f (x), x), _rf_findmin, domain)
860- _rf_findmin ((fm, m), (fx, x)) = isgreater (fm, fx) ? (fx, x) : (fm, m)
861-
862- findmin (a) = _findmin (a, :)
871+ findmin (itr) = _findmin (itr, :)
863872_findmin (a, :: Colon ) = mapfoldl ( ((k, v),) -> (v, k), _rf_findmin, pairs (a) )
864873
865874"""
866875 argmax(f, domain)
867- argmax(f)
868876
869877Return a value `x` in the domain of `f` for which `f(x)` is maximised.
870878If there are multiple maximal values for `f(x)` then the first one will be found.
871879
872- When `domain` is provided it may be any iterable and must not be empty.
873-
874- When `domain` is omitted, `f` must have an implicit domain. In particular, if
875- `f` is an indexable collection, it is interpreted as a function mapping keys
876- (domain) to values (codomain), i.e. `argmax(itr)` returns the index of the
877- maximal element in `itr`.
880+ `domain` must be a non-empty iterable.
878881
879882Values are compared with `isless`.
880883
@@ -885,7 +888,22 @@ julia> argmax(abs, -10:5)
885888
886889julia> argmax(cos, 0:π/2:2π)
8878900.0
891+ ```
892+ """
893+ argmax (f, domain) = findmax (f, domain)[2 ]
888894
895+ """
896+ argmax(itr)
897+
898+ Return the index or key of the maximal element in a collection.
899+ If there are multiple maximal elements, then the first one will be returned.
900+
901+ The collection must not be empty.
902+
903+ Values are compared with `isless`.
904+
905+ # Examples
906+ ```jldoctest
889907julia> argmax([8, 0.1, -9, pi])
8909081
891909
@@ -896,22 +914,15 @@ julia> argmax([1, 7, 7, NaN])
8969144
897915```
898916"""
899- argmax (f, domain) = findmax (f, domain)[2 ]
900- argmax (f) = findmax (f)[2 ]
917+ argmax (itr) = findmax (itr)[2 ]
901918
902919"""
903920 argmin(f, domain)
904- argmin(f)
905921
906922Return a value `x` in the domain of `f` for which `f(x)` is minimised.
907923If there are multiple minimal values for `f(x)` then the first one will be found.
908924
909- When `domain` is provided it may be any iterable and must not be empty.
910-
911- When `domain` is omitted, `f` must have an implicit domain. In particular, if
912- `f` is an indexable collection, it is interpreted as a function mapping keys
913- (domain) to values (codomain), i.e. `argmin(itr)` returns the index of the
914- minimal element in `itr`.
925+ `domain` must be a non-empty iterable.
915926
916927`NaN` is treated as less than all other values except `missing`.
917928
@@ -926,6 +937,22 @@ julia> argmin(x -> -x^3 + x^2 - 10, -5:5)
926937julia> argmin(acos, 0:0.1:1)
9279381.0
928939
940+ ```
941+ """
942+ argmin (f, domain) = findmin (f, domain)[2 ]
943+
944+ """
945+ argmin(itr)
946+
947+ Return the index or key of the minimal element in a collection.
948+ If there are multiple minimal elements, then the first one will be returned.
949+
950+ The collection must not be empty.
951+
952+ `NaN` is treated as less than all other values except `missing`.
953+
954+ # Examples
955+ ```jldoctest
929956julia> argmin([8, 0.1, -9, pi])
9309573
931958
@@ -936,8 +963,7 @@ julia> argmin([7, 1, 1, NaN])
9369634
937964```
938965"""
939- argmin (f, domain) = findmin (f, domain)[2 ]
940- argmin (f) = findmin (f)[2 ]
966+ argmin (itr) = findmin (itr)[2 ]
941967
942968# # all & any
943969
0 commit comments