Map (functional programming)
Appearance
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. map pred list; in Haskell[1] and Scheme.[2] map(pred, array); in Julia, Python,[3] PHP, and R. array.map(pred); in JavaScript, Kotlin, and V (Vlang).[4]
Examples
[change | change source]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
[change | change source]- ↑
mapin the Haskell Standard Prelude - ↑
mapin SRFI 1 - ↑ "Built-in Functions — Python 3.14.2 documentation". docs.python.org. Retrieved 2026-01-17.
- ↑ Rao, Navule Pavan Kumar (December 10, 2021). Getting Started with V Programming. ISBN 978-1839213434. OCLC 1290492862.