pub struct Chain<T> { /* private fields */ }Expand description
Chain wrapper for synchronous operations.
This struct provides a fluent interface for chaining collection operations.
Operations are lazily evaluated and only executed when collect() or value() is called.
Implementations§
Source§impl<T> Chain<T>where
T: Clone,
impl<T> Chain<T>where
T: Clone,
Sourcepub fn map<F>(self, mapper: F) -> Self
pub fn map<F>(self, mapper: F) -> Self
Apply a map operation to each element.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3])
.map(|x| x * 2)
.collect();
assert_eq!(result, vec![2, 4, 6]);Sourcepub fn filter<F>(self, predicate: F) -> Self
pub fn filter<F>(self, predicate: F) -> Self
Apply a filter operation to each element.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3, 4, 5])
.filter(|x| x % 2 == 0)
.collect();
assert_eq!(result, vec![2, 4]);Sourcepub fn take(self, n: usize) -> Self
pub fn take(self, n: usize) -> Self
Take the first n elements.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3, 4, 5])
.take(3)
.collect();
assert_eq!(result, vec![1, 2, 3]);Sourcepub fn skip(self, n: usize) -> Self
pub fn skip(self, n: usize) -> Self
Skip the first n elements.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3, 4, 5])
.skip(2)
.collect();
assert_eq!(result, vec![3, 4, 5]);Sourcepub fn reverse(self) -> Self
pub fn reverse(self) -> Self
Reverse the order of elements.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3])
.reverse()
.collect();
assert_eq!(result, vec![3, 2, 1]);Sourcepub fn collect(self) -> Vec<T>
pub fn collect(self) -> Vec<T>
Collect the results into a vector.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3])
.map(|x| x * 2)
.collect();
assert_eq!(result, vec![2, 4, 6]);Sourcepub fn value(self) -> Vec<T>
pub fn value(self) -> Vec<T>
Get the final value after applying all operations.
§Examples
use rust_lodash::chain::chain;
let result = chain(&[1, 2, 3])
.map(|x| x * 2)
.value();
assert_eq!(result, vec![2, 4, 6]);Sourcepub fn into_collection(self) -> Collection<T>
pub fn into_collection(self) -> Collection<T>
Convert to a Collection.
§Examples
use rust_lodash::chain::chain;
let collection = chain(&[1, 2, 3])
.map(|x| x * 2)
.into_collection();
assert_eq!(collection.data(), &vec![2, 4, 6]);Auto Trait Implementations§
impl<T> Freeze for Chain<T>
impl<T> !RefUnwindSafe for Chain<T>
impl<T> Send for Chain<T>where
T: Send,
impl<T> Sync for Chain<T>where
T: Sync,
impl<T> Unpin for Chain<T>where
T: Unpin,
impl<T> !UnwindSafe for Chain<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more