Function iteratee

  • Creates a function that invokes fn with the arguments of the created function. If fn is a property name, the created function returns the property value for a given element.

    Type Parameters

    • Iteratee extends string | IterateeFnT<any, any>
    • Fallback = undefined

    Parameters

    • fn: Iteratee

      The value to convert to a callback.

    • Optional fallback: Iteratee extends PropertyKey
          ? Fallback
          : never

      The fallback value to use, in case of fn being a property name.

    Returns Iteratee extends PropertyKey
        ? PropertyAccessorT<Iteratee, Fallback>
        : Iteratee

    The callback.

    Since

    1.0.0

    Example

    const callback = iteratee("foo"); // => (value) => get(value, "foo");

    callback({ foo: "bar" }); // => "bar"

    Example

    const callback = iteratee((foo: { bar: string }) => foo.bar); // => (foo: { bar: string }) => foo.bar;

    callback({ bar: "baz" }); // => "baz"