Chain

Struct Chain 

Source
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,

Source

pub fn new(data: &[T]) -> Self

Create a new chain with the given data.

Source

pub fn map<F>(self, mapper: F) -> Self
where F: Fn(&T) -> T + Send + Sync + 'static,

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]);
Source

pub fn filter<F>(self, predicate: F) -> Self
where F: Fn(&T) -> bool + Send + Sync + 'static,

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]);
Source

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]);
Source

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]);
Source

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]);
Source

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]);
Source

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]);
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V