Skip to content

Commit

Permalink
itertools example
Browse files Browse the repository at this point in the history
  • Loading branch information
Alisha committed Jun 21, 2017
1 parent 90d7961 commit 74ca0d2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,7 @@ chrono = { version = "0.3.1", features = ["serde"] }
clap = "2.24.2"
error-chain = "0.10.0"
flate2 = "0.2.19"
itertools = "0.6.0"
lazy_static = "0.2.8"
libc = "0.2.23"
log = "0.3.8"
Expand Down
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@ Current revision: `stdx` 0.118.0-rc, for Rust 1.18, June 8, 2017.
| Command-line argument parsing | [`clap = "2.24.2"`] | [📖][d-clap] |
| Error handling | [`error-chain = "0.10.0"`] | [📖][d-error-chain] |
| Compression - deflate (gzip) | [`flate2 = "0.2.19"`] | [📖][d-flate2] |
| Iterator functions, macros | [`itertools = "0.6.0"`] | [📖][d-itertools] |
| Global initialization | [`lazy_static = "0.2.8"`] | [📖][d-lazy_static] |
| C interop | [`libc = "0.2.23"`] | [📖][d-libc] |
| Logging | [`log = "0.3.8"`] | [📖][d-log] |
Expand Down Expand Up @@ -148,7 149,7 @@ use and is highly configurable.
```rust
extern crate clap;
use clap::{Arg, App, SubCommand};

fn main() {
let app = App::new("My Super Program")
.version("1.0")
Expand All @@ -172,7 173,7 @@ fn main() {

// Parse the command line arguments
let matches = app.get_matches();

let config = matches.value_of("config").unwrap_or("default.conf");
let input = matches.value_of("INPUT").unwrap();

Expand All @@ -186,7 187,7 @@ fn main() {
("push", Some(sub_matches)) => {},
("commit", Some(sub_matches)) => {},
_ => {},
}
}
}
```

Expand Down Expand Up @@ -303,6 304,42 @@ fn main() { run().unwrap() }
 
 
 



<a id="itertools"></a>
### `itertools = "0.6.0"` &emsp; [📖][d-itertools]

The Rust standard Iterator (hyperlinked) type provides a
powerful abstraction for operating over sequences of values,
and is used pervasively throughout Rust. There are though a number
of common operations one might want to perform on sequences that are
not provided by the standard library, and that's where itertools comes
in. This crate has everything *including* the kitchen sink (in the
form of the `batching` adaptor). Highlights include `dedup`, `group_by`,
`mend_slices`, `merge`, `sorted`, `join` and more.

**Example**: [`examples/itertools.rs`]

```rust
extern crate itertools;

use itertools::{join, max, sorted};

fn main(){
let a = [3, 2, 5, 8, 7];

// Combine all iterator elements into one String,
// seperated by *.
println!("{:?}", join(&a, "*"));
// Return the maximum value of the iterable.
println!("{:?}", max(a.iter()).unwrap());
// Collect all the iterable's elements into a
// sorted vector in ascending order.
println!("{:?}", sorted(a.iter()));
}
```

&nbsp;&NewLine;&nbsp;&NewLine;&nbsp;&NewLine;


<a id="lazy_static"></a>
### `lazy_static = "0.2.8"` &emsp; [📖][d-lazy_static]

Expand Down Expand Up @@ -1115,6 1152,7 @@ copyright is owned by its contributors.
[`clap = "2.24.2"`]: #clap
[`error-chain = "0.10.0"`]: #error-chain
[`flate2 = "0.2.19"`]: #flate2
[`itertools = "0.6.0"`]: #itertools
[`serde_json = "1.0.2"`]: #serde_json
[`lazy_static = "0.2.8"`]: #lazy_static
[`libc = "0.2.23"`]: #libc
Expand All @@ -1140,6 1178,7 @@ copyright is owned by its contributors.
[d-clap]: https://docs.rs/clap/2.24.2/clap/
[d-error-chain]: https://docs.rs/error-chain/0.8.1/error_chain/
[d-flate2]: https://docs.rs/flate2/0.2.19/flate2/
[d-itertools]: https://docs.rs/itertools/0.6.0/itertools/
[d-lazy_static]: https://docs.rs/lazy_static/0.2.8/lazy_static
[d-libc]: https://docs.rs/libc/0.2.23/libc/
[d-log]: https://docs.rs/log/0.3.8/log/
Expand All @@ -1165,6 1204,7 @@ copyright is owned by its contributors.
[`examples/clap.rs`]: examples/clap.rs
[`examples/error-chain.rs`]: examples/error-chain.rs
[`examples/flate2.rs`]: examples/flate2.rs
[`examples/itertools.rs`]: examples/itertools.rs
[`examples/lazy_static.rs`]: examples/lazy_static.rs
[`examples/libc.rs`]: examples/libc.rs
[`examples/log.rs`]: examples/log.rs
Expand Down
16 changes: 16 additions & 0 deletions examples/itertools.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
extern crate itertools;

use itertools::{join, max, sorted};

fn main(){
let a = [3, 2, 5, 8, 7];

// Combine all iterator elements into one String,
// seperated by *.
println!("{:?}", join(&a, "*"));
// Return the maximum value of the iterable.
println!("{:?}", max(a.iter()).unwrap());
// Collect all the iterable's elements into a
// sorted vector in ascending order.
println!("{:?}", sorted(a.iter()));
}

0 comments on commit 74ca0d2

Please sign in to comment.