// @flow

import hasKey from "./hasKey";

import type {Composite, Path} from "./types";

/**
 * Returns value located at the given path or undefined otherwise.
 */
const getIn = (path: Path, composite: Composite) => {
  const [key, ...rest] = path;

  return hasKey(key, composite)
    ? getIn(rest, composite[(key: any)])
    : undefined;
};

export default getIn;

// @flow

import {isLastIndex} from "@jumpn/utils-array";

import get from "./get";
import hasKey from "./hasKey";

import type {Composite, Path} from "./types";

const getInRecur = (index, path, composite) => {
  if (isLastIndex(path, index)) return get(path[index], composite);

  return hasKey(path[index], composite)
    ? getInRecur(index + 1, path, get(path[index], composite))
    : undefined;
};

/**
 * Returns value located at the given path or undefined otherwise.
 */
const getIn = (path: Path, composite: Composite) =>
  path.length === 0 ? undefined : getInRecur(0, path, composite);

export default getIn;

Add logic to handle empty path usecase
fix(src): Add logic to handle empty path usecase
