import thrush from "@unction/thrush"; import reduceValues from "@unction/reducevalues"; import mapValues from "@unction/mapvalues"; import mapValuesWithValueKey from "@unction/mapvalueswithvaluekey"; import nestedApply from "@unction/nestedapply"; import {FoldFunctionType} from "./types"; import {TreeType} from "./types"; export default function treeify (foldingFunctions: Array>) { const [initial, ...remaining] = foldingFunctions; return function treeifyIterators (array: Array): TreeType { return reduceValues( thrush )( initial(array) )( mapValuesWithValueKey( nestedApply(mapValues) )( remaining ) ); }; }