Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/lib/reducers.ts>product

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function product
import { product } from "https://deno.land/x/iter@v3.2.3/lib/reducers.ts";
Finds the product of all items in it.

warning: When ran on an endless iterable without any zeros, this never returns.

Examples

Example 1

import * as iter from "https://deno.land/x/iter";

const myRange = iter.create.range(1, 10);
console.log(iter.product(myRange)); // -> 3628800

// Demonstrating laziness
const rangeWithZero = iter.create.range(-1, 10);
const observerdIter = iter.lazyObserver(
  rangeWithZero,
  (x) => console.log("Processed: " + x),
);
// -> Processed: -1
// -> Processed: 0
console.log(iter.product(observerdIter)); // -> -0

Parameters

it: Iterable<number>
  • The iterable to sum.

Returns

number

The product of all items in it.