Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/ahh/mod.ts>I.nextIf

Idiomatic type-safety functions.
Go to Latest
method I.nextIf
import { I } from "https://deno.land/x/ahh@v0.10.3/mod.ts";

Consume the next value of an Iterator and return it if f returns true.

Examples

Example 1

import { I } from "./mod.ts";

const iter = I.peekable(I.iter([1, 2, 3]));

console.log(I.nextIf(iter, (i) => i < 2)); // 1
console.log(I.nextIf(iter, (i) => i < 2)); // undefined
console.log(iter.next()); // 2

Parameters

iter: Peekable<T>
f: (_: T) => boolean