5 个版本 (3 个破坏性更新)

使用旧的 Rust 2015

0.4.1 2016年1月11日
0.4.0 2015年12月23日
0.3.0 2015年12月22日
0.2.0 2015年12月22日
0.1.0 2015年12月22日

#22 in #tap

MIT/Apache

7KB
108

moreops

license version

一组有用的简单附加方法

用法

[dependencies]
moreops = "*"

示例

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

许可证

许可方式为以下之一

任选其一。

贡献

除非你明确声明,否则根据 Apache-2.0 许可证定义的,你有意提交以包含在工作中的任何贡献,都将如上所述双许可,不附加任何额外的条款或条件。

无运行时依赖