Crates.io | then |
lib.rs | then |
version | 0.1.0 |
source | src |
created_at | 2022-02-04 13:37:34.443242 |
updated_at | 2023-03-04 14:11:23.112689 |
description | bool::then functions but named properly |
homepage | |
repository | https://github.com/rossmacarthur/advent |
max_upload_size | |
id | 526795 |
size | 17,196 |
The standard library named bool::then_some
and bool::then
strangely.
It should have been then
and then_with
. I find it annoying that
expr.then(|| value)
is shorter to type that the more “idiomatic”
expr.then_some(value)
This crate provides these functions under the following names
.some
and .some_with
.
First, add the crate to your Cargo manifest.
cargo add then
Now bring the trait into scope.
use then::Some;
The .some
and .some_with
methods are now available on bool
.
assert_eq!(false.some(0), None);
assert_eq!(true.some_with(Default::default), Some(0));
This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.