Map (functional programming)

A map, in functional programming, is for making a change to each element of a list. A built-in variable, also known as a predicate (or "pred"), may represent each element.

Depending on the language, the code can be arranged differently. ; in Haskellmap in the Haskell Standard Prelude and Scheme.map in SRFI 1 ; in Julia, Python, PHP, and R. ; in JavaScript, Kotlin, and V (Vlang).

 Examples 

In the below, map is used to create a new array.

square x = x * x -- function to square each element
>>> map square [1, 2, 3, 4, 5] -- apply to each element
[1, 4, 9, 16, 25] -- new array with changes

array := [1, 2, 3, 4, 5]
new_array := array.map(it * it) // apply to each element
[1, 4, 9, 16, 25] // new array with changes

 References 

Category:Computer science
Category:Computer terminology
Category:Computer programming