Crate moreops [] [src]

A set of useful simple additional methods

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());

// Wrap into tuple
let one = 123.once();
let two = 123.twice();
let three = 123.thrice();

// 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<_, _>>();

Traits

Apply10Ops
Apply11Ops
Apply12Ops
Apply1Ops
Apply2Ops
Apply3Ops
Apply4Ops
Apply5Ops
Apply6Ops
Apply7Ops
Apply8Ops
Apply9Ops
BoolOps
OptionOps
ResultExt
ResultOps
TapOps
TupleOps

Functions

none
once
thrice
twice