Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

loop

import { loop } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/async_iterable.ts";

Transform an AsyncIterable using a stateful stepper function.

@example
import { loop, collect } from "./async_iterable.ts";
import { fromIterable } from "./async_iterable.ts";
import { pipe } from "./fn.ts";

const numbers = fromIterable([1, 2, 3, 4, 5]);
const runningSum = loop(
  (sum: number, value: number) => [sum + value, sum + value],
  0
);

const result = await pipe(
  numbers,
  runningSum,
  collect
);

console.log(result); // [1, 3, 6, 10, 15]
function loop<A, B, S>(stepper: (state: S, value: A) => [S, B], seed: S): (ua: AsyncIterable<A>) => AsyncIterable<B>;
§
loop<A, B, S>(stepper: (state: S, value: A) => [S, B], seed: S): (ua: AsyncIterable<A>) => AsyncIterable<B>
[src]

§Type Parameters

§Parameters

§
stepper: (state: S, value: A) => [S, B]
[src]
§
seed: S
[src]

§Return Type

§
(ua: AsyncIterable<A>) => AsyncIterable<B>
[src]