#utilities #stupid #hash-map #collection #insert #map-value #predule

stupid_utils

A crate that provides some simple and maybe stupid or useful tools

9 releases

new 0.2.7 Jul 9, 2024
0.2.6 May 11, 2024
0.2.4 Sep 28, 2023
0.2.3 Aug 3, 2023
0.1.1 Aug 3, 2023

#1 in #stupid

Download history 10/week @ 2024-03-15 4/week @ 2024-03-22 34/week @ 2024-03-29 8/week @ 2024-04-05 2/week @ 2024-04-19 2/week @ 2024-04-26 318/week @ 2024-05-10 10/week @ 2024-05-17 3/week @ 2024-05-24

615 downloads per month
Used in computercraft_websocket_c…

MIT/Apache

46KB
1K SLoC

Description

A crate that provides some simple and maybe stupid or useful tools

Example

    use std::collections::HashMap;
    use stupid_utils::predule::*;

    let a = HashMap::new().mutable_init(|m| {
        m.insert(1, 4.box_up());
        m.insert(
            2,
            Some(9)
                .map_value(|v| match v {
                    Some(v) => v,
                    None => 3,
                })
                .box_up(),
        );
        let cond = true;
        m.insert(cond.select(3, 4), select(cond, 3, 4).box_up());
    });

    let b = {
        let mut m = HashMap::new();
        m.insert(1, Box::new(4));
        m.insert(
            2,
            Box::new({
                let v = Some(9);
                match v {
                    Some(v) => v,
                    None => 3,
                }
            }),
        );
        let cond = true;
        m.insert(if cond { 3 } else { 4 }, Box::new(if cond { 3 } else { 4 }));
        m
    };

    assert_eq!(a, b);
   

No runtime deps