toOptional

Converts a range or Nullable to an optional type

  1. auto toOptional(R range)
    toOptional
    (
    R
    )
    (
    auto ref R range
    )
    if (
    from.std.range.isInputRange!R
    )
  2. auto toOptional(Nullable!T nullable)

Parameters

range R

the range to convert. It must have no more than 1 element

Return Value

Type: auto

an optional of the element of range or Nullable

Examples

import std.algorithm: map;
import optional;

assert(no!int.map!"a".toOptional == none);
assert(some(1).map!"a".toOptional == some(1));

Meta