Map (higher-order function): Difference between revisions

Content deleted Content added
Undid revision 1228084066 by 201.175.202.119 (talk)
third person
Line 7:
The concept of a map is not limited to lists: it works for sequential [[Container (abstract data type)|containers]], tree-like containers, or even abstract containers such as [[futures and promises]].
 
== Examples: mapping a list ==
 
Suppose wethere have ais list of integers <code>[1, 2, 3, 4, 5]</code> and would like to calculate the [[Square (algebra)|square]] of each integer. To do this, we first define a function to <code>square</code> a single number (shown here in [[Haskell (programming language)|Haskell]]):
 
<syntaxhighlight lang="haskell">
Line 15:
</syntaxhighlight>
 
Afterwards we may, call:
 
<syntaxhighlight lang="haskell">
Line 24:
 
=== Visual example ===
Below, youthere can see ais view of each step of the mapping process for a list of integers <code>X = [0, 5, 8, 3, 2, 1]</code> that we want to mapmapping into a new list <code>X'</code> according to the function <math>f(x) = x + 1</math> :
 
[[File:Mapping-steps-loillibe-new.gif|alt=applying map function processing steps|none|thumb|480x480px|View of processing steps when applying map function on a list]]
Line 36:
</syntaxhighlight>
 
== Generalization ==
 
{{see also|Functor|Category theory}}