#functional #pipe #scope

no-std scopefn

Scope functions for Rust

2 releases

0.0.2 Jun 2, 2024
0.0.1 Jun 2, 2024

#1014 in Rust patterns

Download history 24/week @ 2024-06-16 2/week @ 2024-06-23 5/week @ 2024-08-25 4/week @ 2024-09-01 5/week @ 2024-09-15 33/week @ 2024-09-22 30/week @ 2024-09-29

68 downloads per month
Used in 3 crates (2 directly)

MIT license

6KB
74 lines

scopefn

scopefn is a Rust crate that provides scope functions which inspired by Kotlin's scope functions. It allows you to write more concise and expressive code by providing a set of functions that operate on a value within a specific scope.

Example Usage

Debugging

fn with_debug(data: Vec<i32>) -> Vec<i32> {
    data
        .apply(|d| debug!(d))
        .do_what_you_want()
        .apply(|d| debug!(d))
}

Sorting

fn sort_them(data: Vec<i32>) -> Vec<i32> {
    data.apply_mut(|d| d.sort())
}

Dependencies

~12KB