-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1266 from SRetip/iter_tools_fix
READY : Iter tools fix
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
//! qqq : write proper description | ||
//! This example demonstrates the usage of some standard and non-standard functions | ||
//! from the `iter_tools` crate. The `iter_tools` crate provides additional iterator | ||
//! methods beyond those provided by the standard library. | ||
#[ cfg( not( feature = "enabled" ) ) ] | ||
fn main() {} | ||
|
||
#[ cfg( feature = "enabled" ) ] | ||
fn main() | ||
{ | ||
// Importing functions from the `iter_tools` crate | ||
use iter_tools::*; | ||
|
||
/* standard functions */ | ||
// Creating a vector | ||
let vec = vec![ 5, 1, -2 ]; | ||
// Finding the minimum value in the vector | ||
let min = min( &vec ); | ||
assert_eq!( *min.unwrap(), -2 ); | ||
|
||
/* non standard functions */ | ||
// Creating another vector | ||
let vec = vec![ 5, 1, -2 ]; | ||
let added = vec![ "a", "b", "c" ]; | ||
// Initializing an empty vector to store the result | ||
let mut result = vec![]; | ||
let zipped = zip( &vec, &added ); | ||
for( left, right ) in zipped | ||
// Reversing the vector using the `rev` function from `iter_tools` | ||
let reversed = rev( &vec ); | ||
// Iterating over the reversed vector | ||
for v in reversed | ||
{ | ||
result.push( ( *left, *right ) ); | ||
// Pushing the dereferenced value into the result vector | ||
result.push( *v ); | ||
} | ||
assert_eq!( result, vec![ ( 5, "a" ), ( 1, "b" ), ( -2, "c" ) ] ); | ||
assert_eq!( result, vec![ -2, 1, 5, ] ); | ||
|
||
} |