Coder Social home page Coder Social logo

ksxgithub / tap-trait Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 13 KB

Inspect and mutate values without leaving the method chain

Home Page: https://crates.io/crates/tap-trait

License: MIT License

Rust 100.00%
rust rust-patterns no-std tap trait crate chain

tap-trait's Introduction

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.

tap-trait's People

Contributors

dependabot[bot] avatar ksxgithub avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

tap-trait's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.