Introduce when_else()
This commit is contained in:
parent
256f0308ae
commit
8fc15c05c5
1 changed files with 18 additions and 0 deletions
|
@ -69,6 +69,24 @@ pub trait IntoElement: Sized {
|
||||||
self.map(|this| if condition { then(this) } else { this })
|
self.map(|this| if condition { then(this) } else { this })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn when_else(
|
||||||
|
self,
|
||||||
|
condition: bool,
|
||||||
|
then: impl FnOnce(Self) -> Self,
|
||||||
|
otherwise: impl FnOnce(Self) -> Self,
|
||||||
|
) -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.map(|this| {
|
||||||
|
if condition {
|
||||||
|
then(this)
|
||||||
|
} else {
|
||||||
|
otherwise(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
|
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue