tap-trait

Crates.iotap-trait
lib.rstap-trait
version1.0.0
sourcesrc
created_at2021-07-26 08:04:25.696165
updated_at2021-07-26 08:09:46.1258
descriptionInspect and mutate values without leaving the method chain
homepage
repositoryhttps://github.com/KSXGitHub/tap-trait.git
max_upload_size
id427301
size6,231
Khải (KSXGitHub)

documentation

https://docs.rs/tap-trait

README

Tap Trait

Test Crates.io Version

Inspect and mutate values without leaving the method chain.

Example

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");

License

MIT © Hoàng Văn Khải.

Commit count: 9

cargo fmt