Function toOptional

Converts a range or Nullable to an optional type

auto toOptional(R) (
  auto ref R range
)
if (from.std.range.isInputRange!R);

auto toOptional(T) (
  auto inout ref Nullable!T nullable
);

Parameters

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

Returns

an optional of the element of range or Nullable

Example

import std.algorithm: map;
import optional;

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