until

Lazily iterates range until the element e for which pred(e, sentinel) is true.

This is similar to takeWhile in other languages.

  1. Until!(pred, Range, Sentinel) until(Range range, Sentinel sentinel, OpenRight openRight)
    Until!(pred, Range, Sentinel)
    until
    (
    alias pred = "a == b"
    Range
    Sentinel
    )
    (
    Range range
    ,
    Sentinel sentinel
    ,
    OpenRight openRight = Yes.openRight
    )
    if (
    !is(Sentinel == OpenRight)
    )
  2. Until!(pred, Range, void) until(Range range, OpenRight openRight)

Parameters

pred

Predicate to determine when to stop.

range Range

The input range to iterate over.

sentinel Sentinel

The element to stop at.

openRight OpenRight

Determines whether the element for which the given predicate is true should be included in the resulting range (No.openRight), or not (Yes.openRight).

Return Value

Type: Until!(pred, Range, Sentinel)

An input range that iterates over the original range's elements, but ends when the specified predicate becomes true. If the original range is a forward range or higher, this range will be a forward range.

Examples

import std.algorithm.comparison : equal;
import std.typecons : No;
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
assert(equal(a.until(7), [1, 2, 4]));
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7]));

Meta