Skip to content

unctionjs/flatten

Repository files navigation

@unction/flatten

Tests Stability Dependencies

ListType<Array | Set | Record<string | number | symbol, B> | Map<B, A> | string | A> | RecordType<unknown, Array | Set | Record<string | number | symbol, B> | Map<B, A> | string | A> | string => Array | Set | Record<string | number | symbol, B> | Map<B, A> | string

Takes a multi-dimensional enumerable and decreases the nesting by one.

import {from} from "most"

flatten([["a", "b"], ["c", "d"]]) // ["a", "b", "c", "d"]
flatten(["a", "b", ["c", "d"]]) // ["a", "b", "c", "d"]
flatten(
  from([
    from(["a", "b"]),
    from(["c", "d"]),
  ])
) // ---a---b---c---d---|