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?
Thank you! We'll create more content like this.
Thank you for helping us improve!