Mojo function
product
product[IterableTypeA: Iterable, IterableTypeB: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB) -> _Product2[IterableTypeA.IteratorType[iterable_a_is_mut, origin_of(iterable_a), origin_of(iterable_a)], IterableTypeB.IteratorType[iterable_b_is_mut, origin_of(iterable_b), origin_of(iterable_b)](Copyable & Iterator)]
Returns an iterator that yields tuples of the elements of the outer product of the iterables.
Examples:
var l = ["hey", "hi", "hello"]
var l2 = [10, 20, 30]
for a, b in product(l, l2):
print(a, b)Parameters:
- IterableTypeA (
Iterable): The type of the first iterable. - IterableTypeB (
Iterable): The type of the second iterable.
Args:
- iterable_a (
IterableTypeA): The first iterable. - iterable_b (
IterableTypeB): The second iterable.
Returns:
_Product2: A product iterator that yields outer product tuples of elements from both
iterables.
product[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC) -> _Product3[IterableTypeA.IteratorType[iterable_a_is_mut, origin_of(iterable_a), origin_of(iterable_a)], IterableTypeB.IteratorType[iterable_b_is_mut, origin_of(iterable_b), origin_of(iterable_b)](Copyable & Iterator), IterableTypeC.IteratorType[iterable_c_is_mut, origin_of(iterable_c), origin_of(iterable_c)](Copyable & Iterator)]
Returns an iterator that yields tuples of the elements of the outer product of three iterables.
Examples:
var l1 = [1, 2]
var l2 = [3, 4]
var l3 = [5, 6]
for a, b, c in product(l1, l2, l3):
print(a, b, c)Parameters:
- IterableTypeA (
Iterable): The type of the first iterable. - IterableTypeB (
Iterable): The type of the second iterable. - IterableTypeC (
Iterable): The type of the third iterable.
Args:
- iterable_a (
IterableTypeA): The first iterable. - iterable_b (
IterableTypeB): The second iterable. - iterable_c (
IterableTypeC): The third iterable.
Returns:
_Product3: A product iterator that yields outer product tuples of elements from all
three iterables.
product[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable, IterableTypeD: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC, ref iterable_d: IterableTypeD) -> _Product4[IterableTypeA.IteratorType[iterable_a_is_mut, origin_of(iterable_a), origin_of(iterable_a)], IterableTypeB.IteratorType[iterable_b_is_mut, origin_of(iterable_b), origin_of(iterable_b)](Copyable & Iterator), IterableTypeC.IteratorType[iterable_c_is_mut, origin_of(iterable_c), origin_of(iterable_c)](Copyable & Iterator), IterableTypeD.IteratorType[iterable_d_is_mut, origin_of(iterable_d), origin_of(iterable_d)](Copyable & Iterator)]
Returns an iterator that yields tuples of the elements of the outer product of four iterables.
Examples:
var l1 = [1, 2]
var l2 = [3, 4]
var l3 = [5, 6]
var l4 = [7, 8]
for a, b, c, d in product(l1, l2, l3, l4):
print(a, b, c, d)Parameters:
- IterableTypeA (
Iterable): The type of the first iterable. - IterableTypeB (
Iterable): The type of the second iterable. - IterableTypeC (
Iterable): The type of the third iterable. - IterableTypeD (
Iterable): The type of the fourth iterable.
Args:
- iterable_a (
IterableTypeA): The first iterable. - iterable_b (
IterableTypeB): The second iterable. - iterable_c (
IterableTypeC): The third iterable. - iterable_d (
IterableTypeD): The fourth iterable.
Returns:
_Product4: A product iterator that yields outer product tuples of elements from all
four iterables.
product(var iterable_a: T, var iterable_b: T) -> _Product2[T.IteratorOwnedType, T.IteratorOwnedType(Copyable & Iterator)] where conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable)
Returns an iterator that yields tuples of the elements of the outer product of the iterables, consuming both iterables.
Args:
- iterable_a (
T): The first iterable to consume. - iterable_b (
T): The second iterable to consume.
Returns:
_Product2: A product iterator that yields outer product tuples of elements from both
iterables.
product(var iterable_a: T, var iterable_b: T, var iterable_c: T) -> _Product3[T.IteratorOwnedType, T.IteratorOwnedType(Copyable & Iterator), T.IteratorOwnedType(Copyable & Iterator)] where conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable) if conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable) else conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable)
Returns an iterator that yields tuples of the elements of the outer product of three iterables, consuming all three iterables.
Args:
- iterable_a (
T): The first iterable to consume. - iterable_b (
T): The second iterable to consume. - iterable_c (
T): The third iterable to consume.
Returns:
_Product3: A product iterator that yields outer product tuples of elements from all
three iterables.
product(var iterable_a: T, var iterable_b: T, var iterable_c: T, var iterable_d: T) -> _Product4[T.IteratorOwnedType, T.IteratorOwnedType(Copyable & Iterator), T.IteratorOwnedType(Copyable & Iterator), T.IteratorOwnedType(Copyable & Iterator)] where conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable) if conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable) else conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable) and conforms_to(T.IteratorOwnedType, AnyType & Copyable & Movable)
Returns an iterator that yields tuples of the elements of the outer product of four iterables, consuming all four iterables.
Args:
- iterable_a (
T): The first iterable to consume. - iterable_b (
T): The second iterable to consume. - iterable_c (
T): The third iterable to consume. - iterable_d (
T): The fourth iterable to consume.
Returns:
_Product4: A product iterator that yields outer product tuples of elements from all
four iterables.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!