From fb73b6209c410b731b2857e06f9f0a8d160af24d Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Fri, 30 Mar 2018 10:37:17 -0400 Subject: [PATCH 1/2] Followup to addition of apply * inline code words easiest as backticks * prefer https to http * apply should not be "opinionated" about value vs reference, just transparently pass arguments through --- std/typecons.d | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index 1688c030559..cc3e23eebd6 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), +When called on a $(D Nullable), `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. +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)); From abdce335024beade48a16636e467baf395683aa4 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Fri, 30 Mar 2018 10:38:12 -0400 Subject: [PATCH 2/2] Update typecons.d --- std/typecons.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index cc3e23eebd6..353cc8dd56e 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -3445,9 +3445,9 @@ if (is (typeof(nullValue) == T)) /** Unpacks the content of a $(D Nullable), performs an operation and packs it again. Does nothing if isNull. -When called on a $(D Nullable), `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, `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 `Nullable`