Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kstep/moreops
More fancy operations on Rust types
https://github.com/kstep/moreops
Last synced: 3 months ago
JSON representation
More fancy operations on Rust types
- Host: GitHub
- URL: https://github.com/kstep/moreops
- Owner: kstep
- License: apache-2.0
- Created: 2015-12-22T14:37:39.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-11T11:47:33.000Z (almost 9 years ago)
- Last Synced: 2024-09-16T19:11:31.748Z (4 months ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
moreops
=======
[![license](http://img.shields.io/crates/l/moreops.png)](https://crates.io/crates/moreops)
[![version](http://img.shields.io/crates/v/moreops.png)](https://crates.io/crates/moreops)A set of useful simple additional methods
Usage:
```toml
[dependencies]
moreops = "*"
```Examples:
```rust
use moreops::*;// Simple wrapping into Option
let some_num = 123.some();
let none_num = none::();// 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
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)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.