1.1.0 • Published 10 years ago

@micro-js/map v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 years ago

map

Build status Git tag NPM version Code style

Map a function over a container of some kind

Installation

$ npm install @micro-js/map

Usage

var map = require('@micro-js/map')

map(add1, [1, 2, 3])          // -> [2, 3, 4]
map(add1, {a: 1, b: 2, c: 3}) // -> {a: 2, b: 3, c: 4}

function add1 (n) {
  return n + 1
}

API

map(fn, container)

  • fn - The function to map over val. Accepts (val, key) and returns a new val to be set at key.
  • container - A container of some kind (objects or arrays at the moment, generators soon too).

Returns: A new entity of the same type as container with all of its values being replaced by the result of fn(val, key).

License

MIT