map
map[origin: ImmutOrigin, IterableType: Iterable, ResultType: Copyable, //, function: def(var IterableType.IteratorType[False, origin._mlir_origin, origin].Element) -> ResultType](ref[origin] iterable: IterableType) -> _MapIterator[function]
Returns an iterator that applies function to each element of the input iterable.
Examples:
var l = [1, 2, 3]
def add_one(x: Int) -> Int:
return x + 1
var m = map[add_one](l)
# outputs:
# 2
# 3
# 4
for elem in m:
print(elem)
Parameters:
- origin (
ImmutOrigin): The origin of the iterable. - IterableType (
Iterable): The type of the iterable. - ResultType (
Copyable): The return type of the function. - function (
def(var IterableType.IteratorType[False, origin._mlir_origin, origin].Element) -> ResultType): The function to apply to each element.
Args:
- iterable (
IterableType): The iterable to map over.
Returns:
_MapIterator: A map iterator that yields the results of applying function to each
element.
map[IterableType: IterableOwned, ResultType: Copyable, //, function: def(var IterableType.IteratorOwnedType.Element) -> ResultType](var iterable: IterableType) -> _MapIterator[function]
Returns an iterator that applies function to each element of the input iterable, consuming the iterable.
Parameters:
- IterableType (
IterableOwned): The type of the iterable. - ResultType (
Copyable): The return type of the function. - function (
def(var IterableType.IteratorOwnedType.Element) -> ResultType): The function to apply to each element.
Args:
- iterable (
IterableType): The iterable to consume and map over.
Returns:
_MapIterator: A map iterator that yields the results of applying function to each
element.