Moreops: tiny crate with fancy traits


#1

I gathered a number of little fancy methods and traits into moreops crate.
If you like Scalaz or Haskell, you may like it :wink:

Example usages:

// Wrap into Result/Option
let opt_num = 123.some();
let ok_num = 123.ok();
let err = "Error".to_owned().err();

// Swap Result ok/err variants
let swapped: Result<(), 123> = 123.ok().swap();
let swapped: Result<&'static str, 123> = 123.ok::<&'static str>().swap();

// Wrap into tuple (repeating values as needed)
let once: (i32,) = 123.once();
let twice: (i32, i32) = 123.twice();
let thrice: (i32, i32, i32) = 123.thrice();

// Fance if/else substitution, or bool to Option conversion
let x = (123 % 2 == 0).option("even").unwrap_or("odd");

// Triangle arrows from Scalaz/F# (<|, |>)
let x = (2 * 2).tap(|prod| println!("product: {}", prod));
let x = 2.then(|x| 2 * x);

Upd: This was made just for fun. You are free to like or dislike it.