Function flatMapRecord

  • Converts object to entries, map's it with provided callback and flattens entry list.

    Type Parameters

    • K extends string | number | symbol
    • V
    • RK extends string | number | symbol
    • RV

    Parameters

    • obj: Record<K, V>

      Record like object

    • callback: ((entry) => [RK, RV][])

      map callback, accepts entry pair ([key, value]) and should return list of entry pairs

        • (entry): [RK, RV][]
        • Parameters

          • entry: [K, V]

          Returns [RK, RV][]

    Returns Record<RK, RV>

    new mapped object

    Example

    flatMapRecord({'a': 2}, ([k, v]) => [[k, v]])
    >> {'a': 2, 'b': 3}
    flatMapRecord({'a': 2, 'b': 3}, ([k, v]) => v === 2 ? [[k, v]] : [])
    >> {'a': 2}