5 releases (3 breaking)

Uses old Rust 2015

0.4.1 Jan 11, 2016
0.4.0 Dec 23, 2015
0.3.0 Dec 22, 2015
0.2.0 Dec 22, 2015
0.1.0 Dec 22, 2015

#22 in #tap

MIT/Apache

7KB
108 lines

moreops

license version

A set of useful simple additional methods

Usage:

[dependencies]
moreops = "*"

Examples:

use moreops::*;

// Simple wrapping into Option
let some_num = 123.some();
let none_num = none::<i32>();

// Simple wrapping into Result
let ok = 123.ok();
let err = "Error!".to_owned().err();

// If-like operations with Option
let x = 42;
let answer = (x % 2 == 0).option("even").unwrap_or("odd");

// Tap into some result (like `<|` and `|>` operators from Scalaz)
fn f() -> i32 {
    123
}
assert_eq!(f().tap(|x| println!("{:?}", x)), 123);
assert_eq!(f().pipe(|x| x * 2), 246);

// Swap result
assert_eq!(123.ok().swap(), 123.err());
assert_eq!(123.ok().swap().swap(), 123.ok());

// Apply functions to tuples of args directly
let x = (2, 3, 4).apply(|a, b, c| a * b * c);
assert_eq!(x, 24);

// Use twice() to build map
let map = (1..10).map(twice).collect::<::std::collections::BTreeMap<_, _>>();

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps