Skip to content

Commit

Permalink
Merge pull request #3913 from JakobOvrum/std_algorithm_table_either
Browse files Browse the repository at this point in the history
Tweak std.algorithm.comparison.either docs and add to package doc table
  • Loading branch information
H. S. Teoh committed Mar 9, 2016
2 parents afc4028 + 22a90f9 commit 5dc9102
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions std/algorithm/comparison.d
Expand Up @@ -1962,24 +1962,24 @@ bool isPermutation(alias pred = "a == b", Range1, Range2)
}

/**
Get first parameter $(D p) that passes an $(D if (unaryFun!pred(p))) test. If
no parameter passes the test return the last.
Get the _first argument `a` that passes an `if (unaryFun!pred(a))` test. If
no argument passes the test, return the last argument.
Similar to behaviour of `or` operator in dynamic languages such as Lisp's
Similar to behaviour of the `or` operator in dynamic languages such as Lisp's
`(or ...)` and Python's `a or b or ...` except that the last argument is
returned upon no match.
Simplifies logic, for instance, in parsing rules where a set of alternative
matchers are tried. The first one that matches returns it match result,
matchers are tried. The _first one that matches returns it match result,
typically as an abstract syntax tree (AST).
NOTE: Lazy parameters are currently, too restrictively, inferred by DMD to
always throw eventhough they don't need to be. This makes it impossible to
currently mark $(D either) as $(D nothrow). See issue at
https://issues.dlang.org/show_bug.cgi?id=12647
Bugs:
Lazy parameters are currently, too restrictively, inferred by DMD to
always throw even though they don't need to be. This makes it impossible to
currently mark `either` as `nothrow`. See issue at $(BUGZILLA 12647).
Returns:
The first parameter that passes the test $(D pred).
The _first argument that passes the test `pred`.
*/
CommonType!(T, Ts) either(alias pred = a => a, T, Ts...)(T first, lazy Ts alternatives)
if (alternatives.length >= 1 &&
Expand Down
1 change: 1 addition & 0 deletions std/algorithm/package.d
Expand Up @@ -49,6 +49,7 @@ $(TR $(TDNW Comparison)
$(SUBREF comparison, castSwitch)
$(SUBREF comparison, clamp)
$(SUBREF comparison, cmp)
$(SUBREF comparison, either)
$(SUBREF comparison, equal)
$(SUBREF comparison, isPermutation)
$(SUBREF comparison, isSameLength)
Expand Down

0 comments on commit 5dc9102

Please sign in to comment.