Lazy

Struct Lazy 

Source
pub struct Lazy<T>(/* private fields */);
Expand description

A lazy evaluated Semigroup with nonempty buffer that is implemented by Vec.

§Properties

crate::Annotatecrate::Monoidcrate::Commutative
impl
whereT: crate::Commutative

§Examples

use semigroup::{op::Coalesce, Lazy, Semigroup};

let a = Coalesce(Some(1));
let b = Coalesce(Some(2));
let c = Coalesce(Some(3));

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.first(), &Coalesce(Some(1)));
assert_eq!(lazy.last(), &Coalesce(Some(3)));
assert_eq!(lazy.combine(), Coalesce(Some(1)));

Implementations§

Source§

impl<T: Semigroup> Lazy<T>

Source

pub fn combine(self) -> T

Evaluates Lazy buffer.

§Examples
use semigroup::{op::Coalesce, Lazy, Semigroup};
let a = Coalesce(Some(1));
let b = Coalesce(Some(2));
let c = Coalesce(Some(3));

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());
assert_eq!(lazy.combine(), Coalesce(Some(1)));
Source

pub fn combine_cloned(&self) -> T
where T: Clone,

Evaluates Lazy buffer like Lazy::combine by cloning each element.

§Examples
use semigroup::{op::Coalesce, Lazy, Semigroup};
let a = Coalesce(Some(1));
let b = Coalesce(Some(2));
let c = Coalesce(Some(3));

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());
assert_eq!(lazy.combine_cloned(), Coalesce(Some(1)));
Source

pub fn combine_rev(self) -> T

Evaluates Lazy buffer in reverse order.

§Examples
use semigroup::{op::Coalesce, Lazy, Semigroup};
let a = Coalesce(Some(1));
let b = Coalesce(Some(2));
let c = Coalesce(Some(3));

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());
assert_eq!(lazy.combine_rev(), Coalesce(Some(3)));
Source

pub fn combine_rev_cloned(&self) -> T
where T: Clone,

Evaluates Lazy buffer in reverse order like Lazy::combine_rev by cloning each element.

§Examples
use semigroup::{op::Coalesce, Lazy, Semigroup};
let a = Coalesce(Some(1));
let b = Coalesce(Some(2));
let c = Coalesce(Some(3));

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());
assert_eq!(lazy.combine_rev_cloned(), Coalesce(Some(3)));
Source§

impl<T> Lazy<T>

Source

pub fn from_iterator<I: IntoIterator<Item = T>>(iter: I) -> Option<Self>

Create Lazy from iterator. Used by crate::CombineIterator::collect_lazy.

Source

pub fn is_empty(&self) -> bool

Returns true if the Lazy buffer contains no elements. It is nonempty, so always returns false.

Source

pub fn is_single(&self) -> bool

Returns true if the Lazy buffer contains exactly one element.

Source

pub fn len(&self) -> usize

Returns the number of elements in the Lazy buffer. It is nonempty, so always returns 1 or more.

Source

pub fn first(&self) -> &T

Returns a reference to the first element of the Lazy buffer.

Source

pub fn split_first(&self) -> (&T, &[T])

Returns the reference to the first element and all the rest elements of the Lazy buffer.

Source

pub fn split_off_first(self) -> (T, Vec<T>)

Returns the first element and all the rest elements of the Lazy buffer.

Source

pub fn last(&self) -> &T

Returns a reference to the last element of the Lazy buffer.

Source

pub fn split_last(&self) -> (&T, &[T])

Returns the reference to the last element and all the rest elements of the Lazy buffer.

Source

pub fn split_off_last(self) -> (T, Vec<T>)

Returns the last element and all the rest elements of the Lazy buffer.

Source

pub fn get<I: SliceIndex<[T]>>(&self, index: I) -> Option<&I::Output>

Returns an element or slice like Vec.

Source

pub fn iter(&self) -> <&[T] as IntoIterator>::IntoIter

Returns an iterator over of the Lazy buffer.

Source

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> Lazy<U>

Maps each element of the Lazy buffer with a function, and returns a new Lazy buffer.

Source§

impl<T, A: PartialEq> Lazy<Annotated<T, A>>

Source

pub fn find_annotated(&self, annotation: &A) -> Option<&Annotated<T, A>>

O(n), searches for a value that has the given annotation.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.find_annotated(&"edge"), Some(&a));
assert_eq!(lazy.find_annotated(&"middle"), Some(&b));
assert_eq!(lazy.find_annotated(&"where"), None);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));
Source

pub fn position_annotated(&self, annotation: &A) -> Option<usize>

O(n), searches for a value’s index that has the given annotation.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.position_annotated(&"edge"), Some(0));
assert_eq!(lazy.position_annotated(&"middle"), Some(1));
assert_eq!(lazy.position_annotated(&"where"), None);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));
Source

pub fn rfind_annotated(&self, annotation: &A) -> Option<&Annotated<T, A>>

O(n), searches for a value that has the given annotation from the end.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.rfind_annotated(&"edge"), Some(&c));
assert_eq!(lazy.rfind_annotated(&"middle"), Some(&b));
assert_eq!(lazy.rfind_annotated(&"where"), None);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));
Source

pub fn rposition_annotated(&self, annotation: &A) -> Option<usize>

O(n), searches for a value’s index that has the given annotation from the end.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.rposition_annotated(&"edge"), Some(2));
assert_eq!(lazy.rposition_annotated(&"middle"), Some(1));
assert_eq!(lazy.rposition_annotated(&"where"), None);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));
Source

pub fn find_annotated_all<'a>( &'a self, annotation: &'a A, ) -> impl 'a + Iterator<Item = &'a Annotated<T, A>>

O(n), searches for all values that have the given annotation.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.find_annotated_all(&"edge").collect::<Vec<_>>(), vec![&a, &c]);
assert_eq!(lazy.find_annotated_all(&"middle").collect::<Vec<_>>(), vec![&b]);
assert_eq!(lazy.find_annotated_all(&"where").collect::<Vec<_>>(), vec![&a; 0]);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));
Source

pub fn position_annotated_all<'a>( &'a self, annotation: &'a A, ) -> impl 'a + Iterator<Item = usize>

O(n), searches for all values’ indices that have the given annotation.

§Examples
use semigroup::{op::Coalesce, Annotate, Lazy, Semigroup};

let a = Coalesce(Some(1)).annotated("edge");
let b = Coalesce(Some(2)).annotated("middle");
let c = Coalesce(Some(3)).annotated("edge");

let lazy = Lazy::from(a).semigroup(b.into()).semigroup(c.into());

assert_eq!(lazy.position_annotated_all(&"edge").collect::<Vec<_>>(), vec![0, 2]);
assert_eq!(lazy.position_annotated_all(&"middle").collect::<Vec<_>>(), vec![1]);
assert_eq!(lazy.position_annotated_all(&"where").collect::<Vec<_>>(), vec![0; 0]);
assert_eq!(lazy.combine(), Coalesce(Some(1)).annotated("edge"));

Trait Implementations§

Source§

impl<T: Clone> Clone for Lazy<T>

Source§

fn clone(&self) -> Lazy<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Lazy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Extend<T> for Lazy<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> From<T> for Lazy<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Lazy<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, I: SliceIndex<[T]>> Index<I> for Lazy<T>

Source§

type Output = <I as SliceIndex<[T]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IntoIterator for Lazy<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = <Vec<T> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Ord> Ord for Lazy<T>

Source§

fn cmp(&self, other: &Lazy<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Lazy<T>

Source§

fn eq(&self, other: &Lazy<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Lazy<T>

Source§

fn partial_cmp(&self, other: &Lazy<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Semigroup for Lazy<T>

Source§

fn op(base: Self, other: Self) -> Self

Source§

fn semigroup(self, other: Self) -> Self
where Self: Sized,

Source§

impl<T> Commutative for Lazy<T>
where T: Commutative,

Source§

impl<T: Eq> Eq for Lazy<T>

Source§

impl<T> StructuralPartialEq for Lazy<T>

Auto Trait Implementations§

§

impl<T> Freeze for Lazy<T>

§

impl<T> RefUnwindSafe for Lazy<T>
where T: RefUnwindSafe,

§

impl<T> Send for Lazy<T>
where T: Send,

§

impl<T> Sync for Lazy<T>
where T: Sync,

§

impl<T> Unpin for Lazy<T>
where T: Unpin,

§

impl<T> UnwindSafe for Lazy<T>
where T: UnwindSafe,

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> AsyncCommutative for T
where T: Commutative,

Source§

fn fold_stream( stream: impl Stream<Item = Self>, init: Self, ) -> impl Future<Output = Self>
where Self: Sized + Send,

Available on crate feature async only.
Source§

fn reduce_stream( stream: impl Stream<Item = Self> + Unpin, ) -> impl Future<Output = Option<Self>>
where Self: Sized + Send,

Available on crate feature async only.
Source§

fn combine_stream( stream: impl Stream<Item = Self>, ) -> impl Future<Output = Self>
where Self: Sized + Send + Monoid,

Available on crate features async and monoid only.
Source§

impl<T> AsyncSemigroup for T
where T: Semigroup,

Source§

fn async_op(base: Self, other: Self) -> impl Future<Output = Self>
where Self: Sized + Send,

Available on crate feature async only.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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