Add .and_is() / .and_if() to the BoolExt smalltalk.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-21 17:33:25 +00:00
parent 3b4fbb8c1a
commit 5b620a2c37

View File

@@ -4,6 +4,12 @@
pub trait BoolExt {
fn and<T>(self, t: Option<T>) -> Option<T>;
#[must_use]
fn and_is(self, b: bool) -> bool;
#[must_use]
fn and_if<F: FnOnce() -> bool>(self, f: F) -> bool;
fn and_then<T, F: FnOnce() -> Option<T>>(self, f: F) -> Option<T>;
#[must_use]
@@ -55,6 +61,12 @@ impl BoolExt for bool {
#[inline]
fn and<T>(self, t: Option<T>) -> Option<T> { self.then_some(t).flatten() }
#[inline]
fn and_if<F: FnOnce() -> Self>(self, f: F) -> Self { self.and_is(f()) }
#[inline]
fn and_is(self, b: Self) -> Self { self && b }
#[inline]
fn and_then<T, F: FnOnce() -> Option<T>>(self, f: F) -> Option<T> { self.then(f).flatten() }