Skip to content

map

Summary

Apply a function to each element of a list.

Tip

This function is curried.

Tip

Act as a transducer when composed with drop, take or filter.

Description

Take a function fn then a list xs. Return a list of the same type with the result of applying fn to each element of xs.

Examples

Works with arrays and objects.

1
2
3
4
5
6
7
const double = map(x => x + x);

double([1, 2, 3]);
//=> [2, 4, 6]

double({a: 1, b: 2, c: 3});
//=> {a: 2, b: 4, c: 6}

Parameters

Name Type Description
fn function
xs Array or Object

Return

Array or Object