map(tree, options)

Transform the keys and/or values of a tree

JavaScript function underlying the tree:map builtin, with the same parameters and effects. See that page for complete details.

JavaScript usage #

If the second argument to map is a function, that function will be used to map the values of the input tree.

import { map } from "@weborigami/async-tree";

const temperatures = [
  { city: "Portland", celsius: 21 },
  { city: "San Francisco", celsius: 16 },
  { city: "Seattle", celsius: 24 },
];

// Add a Fahrenheit property to each temperature reading
export default map(temperatures, (reading) => ({
  ...reading,
  fahrenheit: 32 + (9 * reading.celsius) / 5,
}));

The above module exports this data:

- city: Portland
  celsius: 21
  fahrenheit: 69.8
- city: San Francisco
  celsius: 16
  fahrenheit: 60.8
- city: Seattle
  celsius: 24
  fahrenheit: 75.2