bool::then
is, to say the least, amazing. However, in a case where preserving the boolean value is required it inflicts a bit of boilerplate upon us:
value
.then(|| {<action>; true})
.unwrap_or(false)
// or
value
.then_some(true)
.inspect(|_| <action>)
.unwrap_or(false)
This is a minor complaint for sure, but wouldn’t it be a little nicer if we had a couple of methods akin to inspect
(let’s call them do
for now)?
value.do_true(|| <action>)
Wouldn’t make even less of a difference in case two branches are needed, but it might still indicate intention clearer:
value
.do_true(|| <action1>)
.do_false(|| <action2>)
// vs
value
.then(|| {<action1>; true})
.unwrap_or_else(|| {<action2>; false})