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");
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.