diff --git a/std/typecons.d b/std/typecons.d index 1688c030559..353cc8dd56e 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -3441,28 +3441,29 @@ if (is (typeof(nullValue) == T)) assert(ntts.to!string() == "2.5"); } +// apply /** Unpacks the content of a $(D Nullable), performs an operation and packs it again. Does nothing if isNull. -When called on a $(D Nullable), $(D apply) will unpack the value contained in the $(D Nullable), -pass it to the function you provide and wrap the result in another $(D Nullable) (if necessary). -If the Nullable is null, $(D apply) will return null itself. +When called on a `Nullable`, `apply` will unpack the value contained in the `Nullable`, +pass it to the function you provide and wrap the result in another `Nullable` (if necessary). +If the `Nullable` is null, `apply` will return null itself. Params: - t = a $(D Nullable) + t = a `Nullable` fun = a function operating on the content of the nullable Returns: `fun(t.get).nullable` if `!t.isNull`, else `Nullable.init`. See also: - $(HTTP en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad, The `Maybe` monad) + $(HTTPS en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad, The `Maybe` monad) */ template apply(alias fun) { import std.functional : unaryFun; - auto apply(T)(T t) + auto apply(T)(auto ref T t) if (isInstanceOf!(Nullable, T) && is(typeof(unaryFun!fun(T.init.get)))) { alias FunType = typeof(unaryFun!fun(T.init.get));