@metreeca/flow - v0.9.21
    Preparing search index...

    Function min

    • Creates a sink selecting the least item of the feed.

      Items are ranked in source order, seeding the result with the first one and retaining only the least ranking item seen so far, so selection stays within constant memory whatever the size of the feed, but never completes on an infinite source; equally ranking items resolve to the first one in source order.

      An empty feed resolves to undefined; callers wanting a default supply it with ??. As ascending ranks null before any other value, a feed carrying null resolves to it unless the comparator states otherwise.

      Tip

      The @metreeca/core order module provides helper functions for assembling complex ranking criteria.

      Type Parameters

      • V

        The type of items in the feed

      Parameters

      • comparator: (a: V, b: V) => number = ascending

        The function establishing the relative order of two items, defaulting to ascending, which ranks values in natural order, placing null first

      Returns Sink<V, V | undefined>

      A sink resolving to the least ranking item of the feed, or to undefined if the feed carried no items

      await pipe(
      (items(3, 1, 2))
      (min())
      ); // 1

      await pipe(
      (items({ age: 30 }, { age: 20 }))
      (min(by(x => x.age)))
      ); // { age: 20 }

      await pipe(
      (items<number>())
      (min())
      ); // undefined