Skip to content

Commit

Permalink
Merge pull request #1266 from SRetip/iter_tools_fix
Browse files Browse the repository at this point in the history
READY : Iter tools fix
  • Loading branch information
Wandalen authored Mar 29, 2024
2 parents 2c463fe + 17bfe0b commit 4e69b3e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions module/core/iter_tools/examples/iter_tools_trivial.rs
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, ] );

}

0 comments on commit 4e69b3e

Please sign in to comment.