Skip to main content

Mojo function

map

map[origin: ImmutableOrigin, IterableType: Iterable, ResultType: Copyable & Movable, //, function: fn(var IterableType.IteratorType[False, origin].Element) -> ResultType](ref [origin] iterable: IterableType) -> _MapIterator[function]

Returns an iterator applies func to each element of the input iterable.

Examples

var l = [1, 2, 3]
fn add_one(x: Int) -> Int:
    return x + 1
var m = map[add_one](l)

# outputs:
# 2
# 3
# 4
for elem in m:
    print(elem)

Returns:

_MapIterator

Was this page helpful?