Skip to content

Commit b235ecd

Browse files
std.typecons.bind: improve documentation
1 parent b0c382a commit b235ecd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

changelog/std-typecons-nullable-bind.dd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Nullable!int square(Nullable!int n)
1010
{
1111
return n.bind!(i => i * i);
1212
}
13+
-----

std/typecons.d

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,16 +3354,27 @@ auto nullable(alias nullValue, T)(T t)
33543354
}
33553355

33563356
/**
3357+
`auto bind(T)(T t) if (isInstanceOf!(Nullable, T) && is(typeof(unaryFun!fun(T.init.get))))`
3358+
33573359
When called on a $(D Nullable), $(D bind) will unpack the value contained in the $(D Nullable),
33583360
pass it to the function you provide and wrap the result in another $(D Nullable) (if necessary).
33593361
If the Nullable is null, $(D bind) will return null itself.
3362+
3363+
Params:
3364+
t = a $(D Nullable)
3365+
fun = a function operating on the content of the nullable
3366+
3367+
Returns:
3368+
`fun(t.get).nullable` if `!t.isNull`, else `Nullable.init`.
3369+
3370+
See also:
3371+
$(HTTP en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad, The `Maybe` monad)
33603372
*/
33613373
template bind(alias fun)
33623374
{
33633375
import std.functional : unaryFun;
33643376

3365-
auto bind(T)(T t)
3366-
if (isInstanceOf!(Nullable, T) && is(typeof(unaryFun!fun(T.init.get))))
3377+
auto bind(T)(T t) if (isInstanceOf!(Nullable, T) && is(typeof(unaryFun!fun(T.init.get))))
33673378
{
33683379
alias FunType = typeof(unaryFun!fun(T.init.get));
33693380

0 commit comments

Comments
 (0)