pub struct Lazy<T>(/* private fields */);Expand description
A lazy evaluated Semigroup with nonempty buffer that is implemented by Vec.
§Properties
crate::Annotate | crate::Monoid | crate::Commutative | |
|---|---|---|---|
| impl | ❌ | ❌ | ✅ |
| where | T: 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>
impl<T: Semigroup> Lazy<T>
Sourcepub fn combine_cloned(&self) -> Twhere
T: Clone,
pub fn combine_cloned(&self) -> Twhere
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)));Sourcepub fn combine_rev(self) -> T
pub fn combine_rev(self) -> T
Sourcepub fn combine_rev_cloned(&self) -> Twhere
T: Clone,
pub fn combine_rev_cloned(&self) -> Twhere
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>
impl<T> Lazy<T>
Sourcepub fn from_iterator<I: IntoIterator<Item = T>>(iter: I) -> Option<Self>
pub fn from_iterator<I: IntoIterator<Item = T>>(iter: I) -> Option<Self>
Create Lazy from iterator. Used by crate::CombineIterator::collect_lazy.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the Lazy buffer contains no elements. It is nonempty, so always returns false.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the Lazy buffer. It is nonempty, so always returns 1 or more.
Sourcepub fn split_first(&self) -> (&T, &[T])
pub fn split_first(&self) -> (&T, &[T])
Returns the reference to the first element and all the rest elements of the Lazy buffer.
Sourcepub fn split_off_first(self) -> (T, Vec<T>)
pub fn split_off_first(self) -> (T, Vec<T>)
Returns the first element and all the rest elements of the Lazy buffer.
Sourcepub fn split_last(&self) -> (&T, &[T])
pub fn split_last(&self) -> (&T, &[T])
Returns the reference to the last element and all the rest elements of the Lazy buffer.
Sourcepub fn split_off_last(self) -> (T, Vec<T>)
pub fn split_off_last(self) -> (T, Vec<T>)
Returns the last element and all the rest elements of the Lazy buffer.
Sourcepub fn get<I: SliceIndex<[T]>>(&self, index: I) -> Option<&I::Output>
pub fn get<I: SliceIndex<[T]>>(&self, index: I) -> Option<&I::Output>
Returns an element or slice like Vec.
Source§impl<T, A: PartialEq> Lazy<Annotated<T, A>>
impl<T, A: PartialEq> Lazy<Annotated<T, A>>
Sourcepub fn find_annotated(&self, annotation: &A) -> Option<&Annotated<T, A>>
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"));Sourcepub fn position_annotated(&self, annotation: &A) -> Option<usize>
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"));Sourcepub fn rfind_annotated(&self, annotation: &A) -> Option<&Annotated<T, A>>
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"));Sourcepub fn rposition_annotated(&self, annotation: &A) -> Option<usize>
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"));Sourcepub fn find_annotated_all<'a>(
&'a self,
annotation: &'a A,
) -> impl 'a + Iterator<Item = &'a Annotated<T, A>>
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"));Sourcepub fn position_annotated_all<'a>(
&'a self,
annotation: &'a A,
) -> impl 'a + Iterator<Item = usize>
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> Extend<T> for Lazy<T>
impl<T> Extend<T> for Lazy<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> IntoIterator for Lazy<T>
impl<T> IntoIterator for Lazy<T>
Source§impl<T: Ord> Ord for Lazy<T>
impl<T: Ord> Ord for Lazy<T>
Source§impl<T: PartialOrd> PartialOrd for Lazy<T>
impl<T: PartialOrd> PartialOrd for Lazy<T>
impl<T> Commutative for Lazy<T>where
T: Commutative,
impl<T: Eq> Eq for Lazy<T>
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> AsyncCommutative for Twhere
T: Commutative,
impl<T> AsyncCommutative for Twhere
T: Commutative,
Source§fn fold_stream(
stream: impl Stream<Item = Self>,
init: Self,
) -> impl Future<Output = Self>
fn fold_stream( stream: impl Stream<Item = Self>, init: Self, ) -> impl Future<Output = Self>
async only.CombineStream::fold_semigroup.Source§fn reduce_stream(
stream: impl Stream<Item = Self> + Unpin,
) -> impl Future<Output = Option<Self>>
fn reduce_stream( stream: impl Stream<Item = Self> + Unpin, ) -> impl Future<Output = Option<Self>>
async only.CombineStream::reduce_semigroup.Source§fn combine_stream(
stream: impl Stream<Item = Self>,
) -> impl Future<Output = Self>
fn combine_stream( stream: impl Stream<Item = Self>, ) -> impl Future<Output = Self>
async and monoid only.CombineStream::combine_monoid.