mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 00:20:26 +03:00
Tweak std.algorithm.comparison.either docs and add to package doc table
This commit is contained in:
parent
42625ce05c
commit
22a90f904e
2 changed files with 10 additions and 9 deletions
|
@ -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
|
Get the _first argument `a` that passes an `if (unaryFun!pred(a))` test. If
|
||||||
no parameter passes the test return the last.
|
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
|
`(or ...)` and Python's `a or b or ...` except that the last argument is
|
||||||
returned upon no match.
|
returned upon no match.
|
||||||
|
|
||||||
Simplifies logic, for instance, in parsing rules where a set of alternative
|
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).
|
typically as an abstract syntax tree (AST).
|
||||||
|
|
||||||
NOTE: Lazy parameters are currently, too restrictively, inferred by DMD to
|
Bugs:
|
||||||
always throw eventhough they don't need to be. This makes it impossible to
|
Lazy parameters are currently, too restrictively, inferred by DMD to
|
||||||
currently mark $(D either) as $(D nothrow). See issue at
|
always throw even though they don't need to be. This makes it impossible to
|
||||||
https://issues.dlang.org/show_bug.cgi?id=12647
|
currently mark `either` as `nothrow`. See issue at $(BUGZILLA 12647).
|
||||||
|
|
||||||
Returns:
|
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)
|
CommonType!(T, Ts) either(alias pred = a => a, T, Ts...)(T first, lazy Ts alternatives)
|
||||||
if (alternatives.length >= 1 &&
|
if (alternatives.length >= 1 &&
|
||||||
|
|
|
@ -49,6 +49,7 @@ $(TR $(TDNW Comparison)
|
||||||
$(SUBREF comparison, castSwitch)
|
$(SUBREF comparison, castSwitch)
|
||||||
$(SUBREF comparison, clamp)
|
$(SUBREF comparison, clamp)
|
||||||
$(SUBREF comparison, cmp)
|
$(SUBREF comparison, cmp)
|
||||||
|
$(SUBREF comparison, either)
|
||||||
$(SUBREF comparison, equal)
|
$(SUBREF comparison, equal)
|
||||||
$(SUBREF comparison, isPermutation)
|
$(SUBREF comparison, isPermutation)
|
||||||
$(SUBREF comparison, isSameLength)
|
$(SUBREF comparison, isSameLength)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue