Namespace Maps

Maps associate keys with values. Several helper functions are provided for working with the standard JS Map class.

Import example

import { Maps } from 'https://unpkg.com/ixfx/dist/data.js';

Adding

  • addKeepingExisting Adds items to a map only if their key does not exist already
  • addObject: Adds an object, assuming each top-level property of an object is a key
  • getOrGenerate: Solves a common scenario of wanting a value by a particular key, or generating it if it doesn't exist

Deleting

Finding/Iterating

  • filter: Yield values that return true for predicate
  • find: Finds the first value that matches a predicate, or undefined if nothing found
  • hasAnyValue: Searches through all keys, returning true if any occurence of value was found
  • hasKeyValue: true if value is stored under a key
  • firstEntryByPredicate: Returns first entry which matches predicate
  • firstEntryByValue: Returns first entry where value matches
  • getClosestIntegerKey: Assuming numeric keys, find the closest to a target value
  • getFromKeys: Given an iterable of keys, returns the first value where the key is present
  • some: true if predicate is true for any value in map

Transforming values

  • mapToArray: Applies a function to convert a map's values to an array
  • mapToObjectTransform: Converts a map to a plain object, but applying a function to values
  • transformMap: Like Array.map, but for Maps. Useful for generating a map as a transform of an input map.

Creating

To some other data

  • toArray: Returns the values of the map as an array
  • toObject: Coverts a Map to a plain object, useful for JSON serialising.

Etc

See also ixfx's Collections module for custom map implementations.

Index

Interfaces

Type Aliases

Functions