@unction/indexby
TypeScript icon, indicating that this package has built-in type declarations

10.13.0 • Public • Published

@unction/indexBy

Tests Stability Dependencies

MapperFunctionType<A, B> => Array | Set => Map<B, A>

Creates a record tree where the key is a computation on the value and the value is the original value.

indexBy(
  key("id")
)([
  {
    id: "aaa",
    name: "Kurtis Rainbolt-Greene",
  },
  {
    id: "bbb",
    name: "Angela Rainbolt-Greene",
  },
])

Which returns:

{
  aaa: {
    id: "aaa",
    name: "Kurtis Rainbolt-Greene",
  },
  bbb: {
    id: "bbb",
    name: "Angela Rainbolt-Greene",
  },
}
indexBy(
  key("id")
)(
  new Set([
    new Map([
      ["id", "aaa"],
      ["name", "Kurtis Rainbolt-Greene"]
    ]),
    new Map([
      ["id", "bbb"],
      ["name", "Angela Rainbolt-Greene"]
    ])
  ])
)

Which returns:

new Map([
  ["aaa", new Map([
    ["id", "aaa"],
    ["name", "Kurtis Rainbolt-Greene"]
  ])],
  ["bbb", new Map([
    ["id", "bbb"],
    ["name", "Angela Rainbolt-Greene"]
  ])],
])

Readme

Keywords

Package Sidebar

Install

npm i @unction/indexby

Weekly Downloads

1

Version

10.13.0

License

SEE LICENSE IN LICENSE

Unpacked Size

20.3 kB

Total Files

7

Last publish

Collaborators

  • krainboltgreene