IndexedCoproduct

Struct IndexedCoproduct 

Source
#[non_exhaustive]
pub struct IndexedCoproduct<K: ArrayKind, F> { pub sources: FiniteFunction<K>, pub values: F, }
Expand description

A finite coproduct of arrows of type A. Pragmatically, it’s a segmented array

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§sources: FiniteFunction<K>

A [‘FiniteFunction’] whose sum is the length of values, and whose target is sum + 1.

§values: F

The concatenation of all arrays in the coproduct.

Implementations§

Source§

impl<K: ArrayKind, F: Clone + HasLen<K>> IndexedCoproduct<K, F>
where K::Type<K::I>: NaturalArray<K>,

Source

pub fn new(sources: FiniteFunction<K>, values: F) -> Option<Self>

Create a new IndexedCoproduct from a FiniteFunction whose target is the sum of its elements. This condition is checked by summing the array.

Source

pub fn from_semifinite( sources: SemifiniteFunction<K, K::I>, values: F, ) -> Option<Self>

Create a IndexedCoproduct from an array of sources by computing their sum to create a FiniteFunction.

Source§

impl<K: ArrayKind, F: Clone + HasLen<K>> IndexedCoproduct<K, F>
where K::Type<K::I>: NaturalArray<K>,

Source

pub fn singleton(values: F) -> Self

Construct a segmented array with a single segment containing values.

Source

pub fn elements(values: F) -> Self

Construct a segmented array with values.len() segments, each containing a single element.

Source

pub fn len(&self) -> K::I

Source

pub fn flatmap_sources<G: Clone>( &self, other: &IndexedCoproduct<K, G>, ) -> IndexedCoproduct<K, G>

Like IndexedCoproduct::flatmap, but where the values of other are already mapped.

Conceptually, suppose we have

self : [[T]]
other: [[U]]

where other defines a sublist for each element of join(self). Then self.flatmap_sources(other) merges sublists of other using the sources of self.

Source§

impl<K: ArrayKind> IndexedCoproduct<K, FiniteFunction<K>>
where K::Type<K::I>: NaturalArray<K>,

Source

pub fn initial(target: K::I) -> Self

The initial object, i.e., the finite coproduct indexed by the empty set Note that the target of sources must be zero for laws to work here.

Source

pub fn tensor( &self, other: &IndexedCoproduct<K, FiniteFunction<K>>, ) -> IndexedCoproduct<K, FiniteFunction<K>>

Source

pub fn map_values(&self, x: &FiniteFunction<K>) -> Option<Self>

Map the values array of an indexed coproduct, leaving the sources unchanged.

Given an indexed coproduct

Σ_{i ∈ I} f_i : Σ_{i ∈ I} A_i → B

and a finite function x : B → C, return a new IndexedCoproduct representing

Σ_{i ∈ I} (f_i ; x) : Σ_{i ∈ I} A_i → C

Returns None if x.source() != B.

Source

pub fn map_semifinite<T>( &self, x: &SemifiniteFunction<K, T>, ) -> Option<IndexedCoproduct<K, SemifiniteFunction<K, T>>>
where K::Type<T>: Array<K, T>,

Same as map_values, but for SemifiniteFunction.

Source

pub fn flatmap(&self, other: &Self) -> Self

Compose two IndexedCoproduct thought of as lists-of-lists. Given

self : Σ_{a ∈ A} s(a) → B      aka A → B*
other : Σ_{b ∈ B} s(b) → C      aka B → C*

we obtain

self.flatmap(other) : Σ_{a ∈ A} s(a) → C     aka A → C*
Source§

impl<K: ArrayKind, F> IndexedCoproduct<K, F>
where K::Type<K::I>: NaturalArray<K>, F: HasLen<K> + Clone, for<'a, 'b> &'a FiniteFunction<K>: Shr<&'b F, Output = Option<F>>, for<'a, 'b> &'a F: Add<&'b F, Output = Option<F>>,

Source

pub fn coproduct(&self, other: &Self) -> Option<Self>

Source

pub fn map_indexes(&self, x: &FiniteFunction<K>) -> Option<Self>

Given an IndexedCoproduct of SemifiniteFunction:

Σ_{i ∈ X} f_i : Σ_{i ∈ X} A_i → B

and a finite function x : W → X

Return a new IndexedCoproduct representing

Σ_{i ∈ W} f_{x(i)} : Σ_{i ∈ W} A_{x(i)} → B
Source

pub fn indexed_values(&self, x: &FiniteFunction<K>) -> Option<F>

Like Self::map_indexes but only returns the values array.

Trait Implementations§

Source§

impl<K: ArrayKind, F: Clone> Clone for IndexedCoproduct<K, F>
where K::Type<K::I>: Clone,

Source§

fn clone(&self) -> Self

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<K: ArrayKind, F: Debug> Debug for IndexedCoproduct<K, F>
where K::Index: Debug,

Source§

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

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

impl<K: ArrayKind, F> HasLen<K> for IndexedCoproduct<K, F>
where K::Type<K::I>: NaturalArray<K>,

Source§

fn len(&self) -> K::I

Source§

fn is_empty(&self) -> bool

Source§

impl<K: ArrayKind> IntoIterator for IndexedCoproduct<K, FiniteFunction<K>>
where K::Type<K::I>: NaturalArray<K>, K::I: Into<usize>,

Source§

type Item = FiniteFunction<K>

The type of the elements being iterated over.
Source§

type IntoIter = IndexedCoproductFiniteFunctionIterator<K>

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<K: ArrayKind, T> IntoIterator for IndexedCoproduct<K, SemifiniteFunction<K, T>>
where K::Type<K::I>: NaturalArray<K>, K::Type<T>: Array<K, T>, K::I: Into<usize>,

Source§

type Item = SemifiniteFunction<K, T>

The type of the elements being iterated over.
Source§

type IntoIter = IndexedCoproductSemifiniteFunctionIterator<K, T>

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<K: ArrayKind, F: PartialEq> PartialEq for IndexedCoproduct<K, F>

Source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<K, F> Freeze for IndexedCoproduct<K, F>
where F: Freeze, <K as ArrayKind>::Index: Freeze, <K as ArrayKind>::I: Freeze,

§

impl<K, F> RefUnwindSafe for IndexedCoproduct<K, F>

§

impl<K, F> Send for IndexedCoproduct<K, F>
where F: Send, <K as ArrayKind>::Index: Send, <K as ArrayKind>::I: Send,

§

impl<K, F> Sync for IndexedCoproduct<K, F>
where F: Sync, <K as ArrayKind>::Index: Sync, <K as ArrayKind>::I: Sync,

§

impl<K, F> Unpin for IndexedCoproduct<K, F>
where F: Unpin, <K as ArrayKind>::Index: Unpin, <K as ArrayKind>::I: Unpin,

§

impl<K, F> UnwindSafe for IndexedCoproduct<K, F>
where F: UnwindSafe, <K as ArrayKind>::Index: UnwindSafe, <K as ArrayKind>::I: 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> 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<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.