minElement

fnauto minElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range)

Iterates the passed range and returns the minimal element. A custom mapping function can be passed to map. In other languages this is sometimes called argmin.

Complexity: O(n) Exactly n - 1 comparisons are needed.

Parameters

mapcustom accessor for the comparison key
rrange from which the minimal element will be selected
seedcustom seed to use as initial element Precondition: If a seed is not given, r must not be empty.

Returns

The minimal element of the passed-in range.

Note

If at least one of the arguments is NaN, the result is an unspecified value.

If you want to ignore NaNs, you can use filter and isNaN to remove them, before applying minElement. Add a suitable seed, to avoid error messages if all elements are NaNs:

---

<range>.filter!(a=>!a.isNaN).minElement(<seed>);

---

If you want to get NaN as a result if a NaN is present in the range, you can use fold and isNaN:

---

<range>.fold!((a,b)=>a.isNaN || b.isNaN ? real.nan : a < b ? a : b);

---

See Also

fnauto minElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)(Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void))

ditto