unique

Transforms own properties of an object using a mapping function.

Signature

unique(object, transform)
(Object 'a, ((String, 'a)) => (String, 'b)) => Object 'b :: throws Error

Documentation

Transforms own properties of an object using a mapping function.

This function is a specialised form of mapEntries that throws when a key collision happens. Throwing makes this function potentially unsafe to use, however it guarantees a consistent behaviour across different ECMAScript versions and VMs.

Properties

Source Code

(object, transform) =>
  mapEntries(object, transform, (result, key, value) => {
    if (result::hasOwnProperty(key)) {
      throw new Error(`The property ${key} already exists in the resulting object.`);
    }
    result[key] = value;
    return result;
  })
Stability
stable
Licence
MIT
Module
folktale/core/object/map-entries
On This Page
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)