andThen

Returns the error contained within the Expected _and then_ another value if there's no error. This function can be used for control flow based on Expected values.

  1. EX andThen(EX exp, EX value)
  2. EX andThen(EX exp)
    @safe ref
    EX
    andThen
    (
    alias pred
    EX
    )
    (
    auto ref EX exp
    )
    if (
    is(EX : Expected!(T, E, H),
    T
    E
    H
    ) &&
    is(typeof(pred()) : EX)
    )

Parameters

exp EX

The Expected to call andThen on

pred

The predicate to call if the there isn't an error

Examples

assert(expected(42).andThen(expected(1)) == 1);
assert(expected(42).andThen!(() => expected(0)) == 0);
assert(expected(42).andThen(unexpected!int("foo")).error == "foo");
assert(expected(42).andThen!(() => unexpected!int("foo")).error == "foo");
assert(unexpected!int("foo").andThen(expected(42)).error == "foo");
assert(unexpected!int("foo").andThen!(() => expected(42)).error == "foo");
assert(unexpected!int("foo").andThen(unexpected!int("bar")).error == "foo");
assert(unexpected!int("foo").andThen!(() => unexpected!int("bar")).error == "foo");

// with void value
assert(expected().andThen!(() => expected()));
assert(expected().andThen!(() => unexpected("foo")).error == "foo");
assert(unexpected("foo").andThen!(() => expected()).error == "foo");

Meta