moreops

Crates.iomoreops
lib.rsmoreops
version0.4.1
sourcesrc
created_at2015-12-22 09:22:22.440151
updated_at2016-01-11 11:48:33.251247
descriptiona set of simple useful additional methods
homepage
repositoryhttps://github.com/kstep/moreops
max_upload_size
id3729
size18,131
Konstantin Stepanov (kstep)

documentation

README

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.

Commit count: 18

cargo fmt