Crates.io | moreops |
lib.rs | moreops |
version | 0.4.1 |
source | src |
created_at | 2015-12-22 09:22:22.440151 |
updated_at | 2016-01-11 11:48:33.251247 |
description | a set of simple useful additional methods |
homepage | |
repository | https://github.com/kstep/moreops |
max_upload_size | |
id | 3729 |
size | 18,131 |
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<_, _>>();
Licensed under either of
at your option.
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.