2022-08-04 17:38:00 +12:00
|
|
|
```doc
|
|
|
|
# LogicalAnd
|
|
|
|
|
|
|
|
Values which wish to implement the `&&` infix operator must implement this protocol.
|
|
|
|
```
|
2022-08-07 16:20:33 +12:00
|
|
|
protocol LogicalAnd, as: do
|
2022-08-04 17:38:00 +12:00
|
|
|
```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.
|
|
|
|
```
|
2022-08-07 16:20:33 +12:00
|
|
|
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()
|
2022-08-04 17:38:00 +12:00
|
|
|
end
|