map
Input Stack:function: List | items: List |
|
⇨ |
Output Stack:List(function(items[0]), ..., function(items[N-1])) | |
|
Create a new list by applying a function to each element of the input list. The function is applied
to each element individually, and the results are collected into a new list. This is a functional
programming concept similar to map operations in other languages.
Parameters
- items: The input list containing elements to be transformed
- function: A list representing the function to apply to each element
Examples
Apply a format function to transform each string in a list:
(,a%s,b%s,),(,(,.netflix.com,),:format,
),:map
Pos | Input | Output |
0 |
List((, .netflix.com, ), :format) |
List(a.netflix.com, b.netflix.com) |
1 |
List(a%s, b%s) |
|
This example takes the list (a%s, b%s)
and applies the function (, .netflix.com, ), :format
to each
element, resulting in a.netflix.com
and b.netflix.com
.
- :each - Execute a function for each element but don't collect results
- :format - String formatting function commonly used with map
- :list - Create lists that can be transformed with map