Crates.io | tap-trait |
lib.rs | tap-trait |
version | 1.0.0 |
source | src |
created_at | 2021-07-26 08:04:25.696165 |
updated_at | 2021-07-26 08:09:46.1258 |
description | Inspect and mutate values without leaving the method chain |
homepage | |
repository | https://github.com/KSXGitHub/tap-trait.git |
max_upload_size | |
id | 427301 |
size | 6,231 |
Inspect and mutate values without leaving the method chain.
use tap_trait::Tap;
use pipe_trait::Pipe;
let result = 2i32
.tap(|x| assert_eq!(x, 2))
.tap_mut(|x| *x += 1)
.tap(|x| assert_eq!(x, 3))
.tap_mut(|x| *x *= 3)
.tap(|x| assert_eq!(x, 9))
.pipe(|x| -x)
.tap(|x| assert_eq!(x, -9))
.pipe_ref(ToString::to_string)
.tap_ref(|x| assert_eq!(x, "-9"))
.tap_mut(|x| *x += ".0")
.tap_ref(|x| assert_eq!(x, "-9.0"));
assert_eq!(result, "-9.0");