Skip to main content

StepWithLoopBrand

Struct StepWithLoopBrand 

Source
pub struct StepWithLoopBrand<A>(/* private fields */);
Expand description

Brand for the partially-applied form of Step with the Loop type filled in.

Trait Implementations§

Source§

impl<LoopType: Clone + 'static> ApplyFirst for StepWithLoopBrand<LoopType>

Source§

fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Combines two contexts, keeping the value from the first context. Read more
Source§

impl<LoopType: Clone + 'static> ApplySecond for StepWithLoopBrand<LoopType>

Source§

fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Combines two contexts, keeping the value from the second context. Read more
Source§

impl<A: Clone> Clone for StepWithLoopBrand<A>

Source§

fn clone(&self) -> StepWithLoopBrand<A>

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<A: Debug> Debug for StepWithLoopBrand<A>

Source§

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

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

impl<A: Default> Default for StepWithLoopBrand<A>

Source§

fn default() -> StepWithLoopBrand<A>

Returns the “default value” for a type. Read more
Source§

impl<LoopType: 'static> Foldable for StepWithLoopBrand<LoopType>

Source§

fn fold_right<'a, FnBrand, A: 'a, B: 'a, F>( func: F, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where F: Fn(A, B) -> B + 'a, FnBrand: CloneableFn + 'a,

Folds the step from the right.

This method performs a right-associative fold of the step.

§Type Signature

forall self a b. Foldable self => ((a, b) -> b, b, self a) -> b

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the elements in the structure.
  • B: The type of the accumulator.
  • F: The type of the folding function.
§Parameters
  • func: The folding function.
  • initial: The initial value.
  • fa: The step to fold.
§Returns

func(a, initial) if fa is Done(a), otherwise initial.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(fold_right::<RcFnBrand, StepWithLoopBrand<()>, _, _, _>(|x, acc| x + acc, 0, Step::Done(5)), 5);
assert_eq!(fold_right::<RcFnBrand, StepWithLoopBrand<i32>, _, _, _>(|x: i32, acc| x + acc, 0, Step::Loop(1)), 0);
Source§

fn fold_left<'a, FnBrand, A: 'a, B: 'a, F>( func: F, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where F: Fn(B, A) -> B + 'a, FnBrand: CloneableFn + 'a,

Folds the step from the left.

This method performs a left-associative fold of the step.

§Type Signature

forall self a b. Foldable self => ((b, a) -> b, b, self a) -> b

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the elements in the structure.
  • B: The type of the accumulator.
  • F: The type of the folding function.
§Parameters
  • func: The folding function.
  • initial: The initial value.
  • fa: The step to fold.
§Returns

func(initial, a) if fa is Done(a), otherwise initial.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(fold_left::<RcFnBrand, StepWithLoopBrand<()>, _, _, _>(|acc, x| acc + x, 0, Step::Done(5)), 5);
assert_eq!(fold_left::<RcFnBrand, StepWithLoopBrand<i32>, _, _, _>(|acc, x: i32| acc + x, 0, Step::Loop(1)), 0);
Source§

fn fold_map<'a, FnBrand, A: 'a, M, F>( func: F, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where M: Monoid + 'a, F: Fn(A) -> M + 'a, FnBrand: CloneableFn + 'a,

Maps the value to a monoid and returns it.

This method maps the element of the step to a monoid and then returns it.

§Type Signature

forall self a m. (Foldable self, Monoid m) => (a -> m, self a) -> m

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the elements in the structure.
  • M: The type of the monoid.
  • F: The type of the mapping function.
§Parameters
  • func: The mapping function.
  • fa: The step to fold.
§Returns

func(a) if fa is Done(a), otherwise M::empty().

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(
    fold_map::<RcFnBrand, StepWithLoopBrand<()>, _, _, _>(|x: i32| x.to_string(), Step::Done(5)),
    "5".to_string()
);
assert_eq!(
    fold_map::<RcFnBrand, StepWithLoopBrand<i32>, _, _, _>(|x: i32| x.to_string(), Step::Loop(1)),
    "".to_string()
);
Source§

impl<LoopType: 'static> Functor for StepWithLoopBrand<LoopType>

Source§

fn map<'a, A: 'a, B: 'a, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
where Func: Fn(A) -> B + 'a,

Maps a function over the done value in the step.

This method applies a function to the done value inside the step, producing a new step with the transformed done value. The loop value remains unchanged.

§Type Signature

forall self a b. Functor self => (a -> b, self a) -> self b

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the done value.
  • B: The type of the result of applying the function.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply to the done value.
  • fa: The step to map over.
§Returns

A new step containing the result of applying the function to the done value.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(map::<StepWithLoopBrand<i32>, _, _, _>(|x: i32| x * 2, Step::<i32, i32>::Done(5)), Step::Done(10));
Source§

impl<A: Hash> Hash for StepWithLoopBrand<A>

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<LoopType: 'static> Kind_cdc7cd43dac7585f for StepWithLoopBrand<LoopType>

Generated implementation of Kind_cdc7cd43dac7585f for StepWithLoopBrand < LoopType >.

Source§

type Of<'a, B: 'a> = Step<LoopType, B>

The applied type.
Source§

impl<LoopType: Clone + 'static> Lift for StepWithLoopBrand<LoopType>

Source§

fn lift2<'a, A, B, C, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>
where Func: Fn(A, B) -> C + 'a, A: Clone + 'a, B: Clone + 'a, C: 'a,

Lifts a binary function into the step context.

This method lifts a binary function to operate on values within the step context.

§Type Signature

forall self a b c. Lift self => ((a, b) -> c, self a, self b) -> self c

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the first value.
  • B: The type of the second value.
  • C: The type of the result.
  • Func: The type of the binary function.
§Parameters
  • func: The binary function to apply.
  • fa: The first step.
  • fb: The second step.
§Returns

Done(f(a, b)) if both steps are Done, otherwise the first loop encountered.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(
    lift2::<StepWithLoopBrand<()>, _, _, _, _>(|x: i32, y: i32| x + y, Step::Done(1), Step::Done(2)),
    Step::Done(3)
);
assert_eq!(
    lift2::<StepWithLoopBrand<i32>, _, _, _, _>(|x: i32, y: i32| x + y, Step::Done(1), Step::Loop(2)),
    Step::Loop(2)
);
Source§

impl<A: Ord> Ord for StepWithLoopBrand<A>

Source§

fn cmp(&self, other: &StepWithLoopBrand<A>) -> 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<LoopType: 'static> ParFoldable for StepWithLoopBrand<LoopType>

Source§

fn par_fold_map<'a, FnBrand, A, M>( func: <FnBrand as SendCloneableFn>::SendOf<'a, A, M>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where FnBrand: 'a + SendCloneableFn, A: 'a + Clone + Send + Sync, M: Monoid + Send + Sync + 'a,

Maps the value to a monoid and returns it, or returns empty, in parallel.

This method maps the element of the step to a monoid and then returns it. The mapping operation may be executed in parallel.

§Type Signature

forall self a m. (ParFoldable self, Monoid m) => (a -> m, self a) -> m

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function wrapper.
  • A: The element type.
  • M: The monoid type.
§Parameters
  • func: The thread-safe function to map each element to a monoid.
  • fa: The step to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};

let x: Step<i32, i32> = Step::Done(5);
let f = send_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x.to_string());
assert_eq!(par_fold_map::<ArcFnBrand, StepWithLoopBrand<i32>, _, _>(f.clone(), x), "5".to_string());

let x_loop: Step<i32, i32> = Step::Loop(1);
assert_eq!(par_fold_map::<ArcFnBrand, StepWithLoopBrand<i32>, _, _>(f, x_loop), "".to_string());
Source§

fn par_fold_right<'a, FnBrand, A, B>( func: <FnBrand as SendCloneableFn>::SendOf<'a, (A, B), B>, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where FnBrand: 'a + SendCloneableFn, A: 'a + Clone + Send + Sync, B: Send + Sync + 'a,

Folds the step from the right in parallel.

This method folds the step by applying a function from right to left, potentially in parallel.

§Type Signature

forall self a b. ParFoldable self => ((a, b) -> b, b, self a) -> b

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function wrapper.
  • A: The element type.
  • B: The accumulator type.
§Parameters
  • func: The thread-safe function to apply to each element and the accumulator.
  • initial: The initial value.
  • fa: The step to fold.
§Returns

The final accumulator value.

§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};

let x: Step<i32, i32> = Step::Done(5);
let f = send_cloneable_fn_new::<ArcFnBrand, _, _>(|(a, b): (i32, i32)| a + b);
assert_eq!(par_fold_right::<ArcFnBrand, StepWithLoopBrand<i32>, _, _>(f.clone(), 10, x), 15);

let x_loop: Step<i32, i32> = Step::Loop(1);
assert_eq!(par_fold_right::<ArcFnBrand, StepWithLoopBrand<i32>, _, _>(f, 10, x_loop), 10);
Source§

impl<A: PartialEq> PartialEq for StepWithLoopBrand<A>

Source§

fn eq(&self, other: &StepWithLoopBrand<A>) -> 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<A: PartialOrd> PartialOrd for StepWithLoopBrand<A>

Source§

fn partial_cmp(&self, other: &StepWithLoopBrand<A>) -> 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<LoopType: 'static> Pointed for StepWithLoopBrand<LoopType>

Source§

fn pure<'a, A: 'a>(a: A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Wraps a value in a step.

This method wraps a value in the Done variant of a Step.

§Type Signature

forall self a. Pointed self => a -> self a

§Type Parameters
  • 'a: The lifetime of the value.
  • A: The type of the value to wrap.
§Parameters
  • a: The value to wrap.
§Returns

Done(a).

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(pure::<StepWithLoopBrand<()>, _>(5), Step::Done(5));
Source§

impl<LoopType: Clone + 'static> Semiapplicative for StepWithLoopBrand<LoopType>

Source§

fn apply<'a, FnBrand: 'a + CloneableFn, A: 'a + Clone, B: 'a>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::Of<'a, A, B>>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Applies a wrapped function to a wrapped value.

This method applies a function wrapped in a step to a value wrapped in a step.

§Type Signature

forall self a b. Semiapplicative self => (self (a -> b), self a) -> self b

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function wrapper.
  • A: The type of the input value.
  • B: The type of the output value.
§Parameters
  • ff: The step containing the function.
  • fa: The step containing the value.
§Returns

Done(f(a)) if both are Done, otherwise the first loop encountered.

§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};

let f: Step<_, _> = Step::Done(cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
assert_eq!(apply::<RcFnBrand, StepWithLoopBrand<()>, _, _>(f, Step::Done(5)), Step::Done(10));
Source§

impl<LoopType: Clone + 'static> Semimonad for StepWithLoopBrand<LoopType>

Source§

fn bind<'a, A: 'a, B: 'a, Func>( ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, func: Func, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
where Func: Fn(A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,

Chains step computations.

This method chains two computations, where the second computation depends on the result of the first.

§Type Signature

forall self a b. Semimonad self => (self a, a -> self b) -> self b

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the result of the first computation.
  • B: The type of the result of the second computation.
  • Func: The type of the function to apply.
§Parameters
  • ma: The first step.
  • func: The function to apply to the value inside the step.
§Returns

The result of applying f to the value if ma is Done, otherwise the original loop.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(
    bind::<StepWithLoopBrand<()>, _, _, _>(Step::Done(5), |x| Step::Done(x * 2)),
    Step::Done(10)
);
Source§

impl<LoopType: Clone + 'static> Traversable for StepWithLoopBrand<LoopType>

Source§

fn traverse<'a, A: 'a + Clone, B: 'a + Clone, F: Applicative, Func>( func: Func, ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where Func: Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Traverses the step with an applicative function.

This method maps the element of the step to a computation, evaluates it, and combines the result into an applicative context.

§Type Signature

forall self a b f. (Traversable self, Applicative f) => (a -> f b, self a) -> f (self b)

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements in the traversable structure.
  • B: The type of the elements in the resulting traversable structure.
  • F: The applicative context.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply.
  • ta: The step to traverse.
§Returns

The step wrapped in the applicative context.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(
    traverse::<StepWithLoopBrand<()>, _, _, OptionBrand, _>(|x| Some(x * 2), Step::Done(5)),
    Some(Step::Done(10))
);
assert_eq!(
    traverse::<StepWithLoopBrand<i32>, _, _, OptionBrand, _>(|x: i32| Some(x * 2), Step::Loop(1)),
    Some(Step::Loop(1))
);
Source§

fn sequence<'a, A: 'a + Clone, F: Applicative>( ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <F as Kind_cdc7cd43dac7585f>::Of<'a, A>>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>>
where <F as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone,

Sequences a step of applicative.

This method evaluates the computation inside the step and accumulates the result into an applicative context.

§Type Signature

forall self a f. (Traversable self, Applicative f) => self (f a) -> f (self a)

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements in the traversable structure.
  • F: The applicative context.
§Parameters
  • ta: The step containing the applicative value.
§Returns

The step wrapped in the applicative context.

§Examples
use fp_library::{brands::*, functions::*, types::*};

assert_eq!(
    sequence::<StepWithLoopBrand<()>, _, OptionBrand>(Step::Done(Some(5))),
    Some(Step::Done(5))
);
assert_eq!(
    sequence::<StepWithLoopBrand<i32>, i32, OptionBrand>(Step::Loop::<i32, Option<i32>>(1)),
    Some(Step::Loop::<i32, i32>(1))
);
Source§

impl<A: Copy> Copy for StepWithLoopBrand<A>

Source§

impl<A: Eq> Eq for StepWithLoopBrand<A>

Source§

impl<A> StructuralPartialEq for StepWithLoopBrand<A>

Auto Trait Implementations§

§

impl<A> Freeze for StepWithLoopBrand<A>

§

impl<A> RefUnwindSafe for StepWithLoopBrand<A>
where A: RefUnwindSafe,

§

impl<A> Send for StepWithLoopBrand<A>
where A: Send,

§

impl<A> Sync for StepWithLoopBrand<A>
where A: Sync,

§

impl<A> Unpin for StepWithLoopBrand<A>
where A: Unpin,

§

impl<A> UnwindSafe for StepWithLoopBrand<A>
where A: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<Brand> Applicative for Brand

Source§

impl<Brand> Monad for Brand
where Brand: Applicative + Semimonad,