import { curry } from '@typed/lambda' import { chain, Maybe } from '@typed/maybe' import { prop } from './prop' import { ObjectPath } from './types' /** * Get value at a given path. */ export const path = curry( (keys: Keys, obj: A): Maybe> => (keys.length === 0 ? Maybe.of(obj) : keys.length === 1 ? prop(keys[0], obj) : keys .slice(1) .reduce( (maybe, key) => chain(prop(key) as any, maybe) as any, prop(keys[0], obj), )) as Maybe>, ) as { (keys: Keys, obj: A): Maybe> (keys: Keys): (obj: A) => Maybe> }