Function path

Given a path in form of a string, returns a function that extracts the value at that path from an object.

const obj = { a: { b: { c: 1 } } } as const;
const a = path('a.b.c')(obj); // 1
const b = path('a.s')(obj); // undefined
  • Type Parameters

    • K extends string

    Parameters

    • key: K

    Returns (<O>(o: O) => PathResult<K, O>)

      • <O>(o): PathResult<K, O>
      • Type Parameters

        • O

        Parameters

        Returns PathResult<K, O>