25 lines
676 B
Text
25 lines
676 B
Text
use Any
|
|
use Boolean
|
|
use Option
|
|
|
|
```doc
|
|
# LogicalAnd
|
|
|
|
Values which wish to implement the `&&` infix operator must implement this protocol.
|
|
```
|
|
protocol LogicalAnd, as: do
|
|
```doc
|
|
Should the value be considered `true` for purposes of an `&&` expression?
|
|
|
|
Must be implemented.
|
|
```
|
|
def true?(self: Self): Boolean
|
|
|
|
```doc
|
|
A short-circuiting logical and operation.
|
|
|
|
If `LogicalAnd.true?` is true for both the left-hand and right-hand values, the right-hand value is returned. Otherwise None.
|
|
```
|
|
def and(self: Self, other: Any): Option, when: true?(self) && true?(other), as: Option.some(other)
|
|
def and(_self: Self, _other: Any): Option, as: Option.none()
|
|
end
|