https://github.com/ksxgithub/tap-trait
Inspect and mutate values without leaving the method chain
https://github.com/ksxgithub/tap-trait
chain crate no-std rust rust-patterns tap trait
Last synced: 22 days ago
JSON representation
Inspect and mutate values without leaving the method chain
- Host: GitHub
- URL: https://github.com/ksxgithub/tap-trait
- Owner: KSXGitHub
- License: mit
- Created: 2021-07-26T08:01:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T05:57:46.000Z (almost 3 years ago)
- Last Synced: 2024-04-25T18:43:17.077Z (almost 2 years ago)
- Topics: chain, crate, no-std, rust, rust-patterns, tap, trait
- Language: Rust
- Homepage: https://crates.io/crates/tap-trait
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Tap Trait
[](https://github.com/KSXGitHub/tap-trait/actions?query=workflow%3ATest)
[](https://crates.io/crates/tap-trait)
Inspect and mutate values without leaving the method chain.
## Example
```rust
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](https://git.io/J4otf) © [Hoàng Văn Khải](https://ksxgithub.github.io/).