Skip to main content

ControlFlowBrand

Struct ControlFlowBrand 

Source
pub struct ControlFlowBrand;
Expand description

Brand for ControlFlow.

The type parameters are swapped relative to ControlFlow<B, C> so that the first HKT parameter is the continue (loop/state) value and the second is the break (done/result) value, matching tail_rec_m conventions.

Implementations§

Source§

impl ControlFlowBrand

Static helper methods for ControlFlow values.

These methods mirror the inherent methods that were previously on the Step type, now provided as associated functions on the brand.

§Higher-Kinded Type Representation

ControlFlow has multiple higher-kinded representations:

Source

pub fn is_continue<B, C>(cf: &ControlFlow<B, C>) -> bool

Returns true if this is a Continue variant.

§Type Signature

forall B C. &ControlFlow B C -> bool

§Type Parameters
  • B: The break type.
  • C: The continue type.
§Parameters
  • cf: The control flow value.
§Returns

true if the value is Continue, false otherwise.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Continue(1);
assert!(ControlFlowBrand::is_continue(&cf));
Source

pub fn is_break<B, C>(cf: &ControlFlow<B, C>) -> bool

Returns true if this is a Break variant.

§Type Signature

forall B C. &ControlFlow B C -> bool

§Type Parameters
  • B: The break type.
  • C: The continue type.
§Parameters
  • cf: The control flow value.
§Returns

true if the value is Break, false otherwise.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Break(1);
assert!(ControlFlowBrand::is_break(&cf));
Source

pub fn map_continue<B, C, C2>( cf: ControlFlow<B, C>, f: impl FnOnce(C) -> C2, ) -> ControlFlow<B, C2>

Maps a function over the Continue variant.

§Type Signature

forall B C C2. (ControlFlow B C, C -> C2) -> ControlFlow B C2

§Type Parameters
  • B: The break type.
  • C: The original continue type.
  • C2: The new continue type.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the continue value.
§Returns

A new ControlFlow with the continue value transformed.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Continue(1);
let mapped = ControlFlowBrand::map_continue(cf, |x| x + 1);
assert_eq!(mapped, ControlFlow::Continue(2));
Source

pub fn map_break<B, C, B2>( cf: ControlFlow<B, C>, f: impl FnOnce(B) -> B2, ) -> ControlFlow<B2, C>

Maps a function over the Break variant.

§Type Signature

forall B C B2. (ControlFlow B C, B -> B2) -> ControlFlow B2 C

§Type Parameters
  • B: The original break type.
  • C: The continue type.
  • B2: The new break type.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the break value.
§Returns

A new ControlFlow with the break value transformed.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Break(1);
let mapped = ControlFlowBrand::map_break(cf, |x| x + 1);
assert_eq!(mapped, ControlFlow::Break(2));
Source

pub fn bimap<B, C, B2, C2>( cf: ControlFlow<B, C>, f: impl FnOnce(C) -> C2, g: impl FnOnce(B) -> B2, ) -> ControlFlow<B2, C2>

Applies functions to both variants (bifunctor map).

§Type Signature

forall B C B2 C2. (ControlFlow B C, C -> C2, B -> B2) -> ControlFlow B2 C2

§Type Parameters
  • B: The original break type.
  • C: The original continue type.
  • B2: The new break type.
  • C2: The new continue type.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the continue value.
  • g: The function to apply to the break value.
§Returns

A new ControlFlow with both values transformed.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Continue(1);
let mapped = ControlFlowBrand::bimap(cf, |x| x + 1, |x| x * 2);
assert_eq!(mapped, ControlFlow::Continue(2));
Source

pub fn bi_fold_right<B, C, Acc>( cf: ControlFlow<B, C>, f: impl FnOnce(C, Acc) -> Acc, g: impl FnOnce(B, Acc) -> Acc, z: Acc, ) -> Acc

Folds the control flow from right to left using two step functions.

See Bifoldable::bi_fold_right for the type class version.

§Type Signature

forall B C Acc. (ControlFlow B C, (C, Acc) -> Acc, (B, Acc) -> Acc, Acc) -> Acc

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • Acc: The accumulator type.
§Parameters
  • cf: The control flow value.
  • f: The step function for the Continue variant.
  • g: The step function for the Break variant.
  • z: The initial accumulator.
§Returns

The result of folding.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(ControlFlowBrand::bi_fold_right(x, |c, acc| acc - c, |b, acc| acc + b, 10), 7);
Source

pub fn bi_fold_left<B, C, Acc>( cf: ControlFlow<B, C>, f: impl FnOnce(Acc, C) -> Acc, g: impl FnOnce(Acc, B) -> Acc, z: Acc, ) -> Acc

Folds the control flow from left to right using two step functions.

See Bifoldable::bi_fold_left for the type class version.

§Type Signature

forall B C Acc. (ControlFlow B C, (Acc, C) -> Acc, (Acc, B) -> Acc, Acc) -> Acc

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • Acc: The accumulator type.
§Parameters
  • cf: The control flow value.
  • f: The step function for the Continue variant.
  • g: The step function for the Break variant.
  • z: The initial accumulator.
§Returns

The result of folding.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, i32> = ControlFlow::Break(5);
assert_eq!(ControlFlowBrand::bi_fold_left(x, |acc, c| acc - c, |acc, b| acc + b, 10), 15);
Source

pub fn bi_fold_map<B, C, M>( cf: ControlFlow<B, C>, f: impl FnOnce(C) -> M, g: impl FnOnce(B) -> M, ) -> M

Maps the value to a monoid depending on the variant.

See Bifoldable::bi_fold_map for the type class version.

§Type Signature

forall B C M. (ControlFlow B C, C -> M, B -> M) -> M

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • M: The monoid type.
§Parameters
  • cf: The control flow value.
  • f: The function mapping the Continue value to the monoid.
  • g: The function mapping the Break value to the monoid.
§Returns

The monoid value.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	ControlFlowBrand::bi_fold_map(x, |c: i32| c.to_string(), |b: i32| b.to_string()),
	"3"
);
Source

pub fn fold_right<B, C, Acc>( cf: ControlFlow<B, C>, f: impl FnOnce(B, Acc) -> Acc, initial: Acc, ) -> Acc

Folds the Break value, returning initial for Continue.

See Foldable::fold_right for the type class version (via ControlFlowContinueAppliedBrand).

§Type Signature

forall B C Acc. (ControlFlow B C, (B, Acc) -> Acc, Acc) -> Acc

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • Acc: The accumulator type.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the Break value and the accumulator.
  • initial: The initial accumulator.
§Returns

The result of folding.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, ()> = ControlFlow::Break(5);
assert_eq!(ControlFlowBrand::fold_right(x, |b, acc| b + acc, 10), 15);
Source

pub fn fold_left<B, C, Acc>( cf: ControlFlow<B, C>, f: impl FnOnce(Acc, B) -> Acc, initial: Acc, ) -> Acc

Folds the Break value from the left, returning initial for Continue.

See Foldable::fold_left for the type class version (via ControlFlowContinueAppliedBrand).

§Type Signature

forall B C Acc. (ControlFlow B C, (Acc, B) -> Acc, Acc) -> Acc

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • Acc: The accumulator type.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the accumulator and the Break value.
  • initial: The initial accumulator.
§Returns

The result of folding.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, ()> = ControlFlow::Break(5);
assert_eq!(ControlFlowBrand::fold_left(x, |acc, b| acc + b, 10), 15);
Source

pub fn fold_map<B, C, M: Monoid>( cf: ControlFlow<B, C>, f: impl FnOnce(B) -> M, ) -> M

Maps the Break value to a monoid, returning M::empty() for Continue.

See Foldable::fold_map for the type class version (via ControlFlowContinueAppliedBrand).

§Type Signature

forall B C M. Monoid M => (ControlFlow B C, B -> M) -> M

§Type Parameters
  • B: The break type.
  • C: The continue type.
  • M: The monoid type.
§Parameters
  • cf: The control flow value.
  • f: The mapping function.
§Returns

The monoid value.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, ()> = ControlFlow::Break(5);
assert_eq!(ControlFlowBrand::fold_map(x, |b: i32| b.to_string()), "5".to_string());
Source

pub fn bind_break<B, C, B2>( cf: ControlFlow<B, C>, f: impl FnOnce(B) -> ControlFlow<B2, C>, ) -> ControlFlow<B2, C>

Chains the Break value into a new computation, passing through Continue.

See Semimonad::bind for the type class version (via ControlFlowContinueAppliedBrand).

§Type Signature

forall B C B2. (ControlFlow B C, B -> ControlFlow B2 C) -> ControlFlow B2 C

§Type Parameters
  • B: The original break type.
  • C: The continue type.
  • B2: The type of the resulting break value.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the Break value.
§Returns

The result of the computation.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, i32> = ControlFlow::Break(5);
let y = ControlFlowBrand::bind_break(x, |b| ControlFlow::Break(b * 2));
assert_eq!(y, ControlFlow::Break(10));
Source

pub fn bind_continue<B, C, C2>( cf: ControlFlow<B, C>, f: impl FnOnce(C) -> ControlFlow<B, C2>, ) -> ControlFlow<B, C2>

Chains the Continue value into a new computation, passing through Break.

See Semimonad::bind for the type class version (via ControlFlowBreakAppliedBrand).

§Type Signature

forall B C C2. (ControlFlow B C, C -> ControlFlow B C2) -> ControlFlow B C2

§Type Parameters
  • B: The break type.
  • C: The original continue type.
  • C2: The type of the resulting continue value.
§Parameters
  • cf: The control flow value.
  • f: The function to apply to the Continue value.
§Returns

The result of the computation.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(5);
let y = ControlFlowBrand::bind_continue(x, |c| ControlFlow::Continue(c * 2));
assert_eq!(y, ControlFlow::Continue(10));
Source

pub fn break_val<B, C>(cf: ControlFlow<B, C>) -> Option<B>

Extracts the Break value, returning None if this is a Continue.

§Type Signature

forall B C. ControlFlow B C -> Option B

§Type Parameters
  • B: The break type.
  • C: The continue type.
§Parameters
  • cf: The control flow value.
§Returns

Some(b) if Break(b), None if Continue(_).

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Break(42);
assert_eq!(ControlFlowBrand::break_val(cf), Some(42));

let cf: ControlFlow<i32, i32> = ControlFlow::Continue(1);
assert_eq!(ControlFlowBrand::break_val(cf), None);
Source

pub fn continue_val<B, C>(cf: ControlFlow<B, C>) -> Option<C>

Extracts the Continue value, returning None if this is Break.

§Type Signature

forall B C. ControlFlow B C -> Option C

§Type Parameters
  • B: The break type.
  • C: The continue type.
§Parameters
  • cf: The control flow value.
§Returns

Some(c) if Continue(c), None if Break(_).

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<i32, i32> = ControlFlow::Continue(7);
assert_eq!(ControlFlowBrand::continue_val(cf), Some(7));

let cf: ControlFlow<i32, i32> = ControlFlow::Break(42);
assert_eq!(ControlFlowBrand::continue_val(cf), None);
Source

pub fn swap<B, C>(cf: ControlFlow<B, C>) -> ControlFlow<C, B>

Swaps the type parameters, mapping Continue(c) to Break(c) and Break(b) to Continue(b).

§Type Signature

forall B C. ControlFlow B C -> ControlFlow C B

§Type Parameters
  • B: The break type.
  • C: The continue type.
§Parameters
  • cf: The control flow value.
§Returns

A new ControlFlow with the variants swapped.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::ControlFlowBrand,
};

let cf: ControlFlow<&str, i32> = ControlFlow::Continue(1);
assert_eq!(ControlFlowBrand::swap(cf), ControlFlow::Break(1));

let cf: ControlFlow<&str, i32> = ControlFlow::Break("hello");
assert_eq!(ControlFlowBrand::swap(cf), ControlFlow::Continue("hello"));
Source

pub fn bi_traverse<'a, B: 'a, C: 'a, C2: 'a + Clone, B2: 'a + Clone, F: Applicative>( cf: ControlFlow<B, C>, f: impl Fn(C) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, C2> + 'a, g: impl Fn(B) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B2> + 'a, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, ControlFlow<B2, C2>>
where ControlFlow<B2, C2>: Clone,

Traverses the control flow with two effectful functions.

See Bitraversable::bi_traverse for the type class version.

§Type Signature

forall B C C2 B2 F. Applicative F => (ControlFlow B C, C -> F C2, B -> F B2) -> F (ControlFlow B2 C2)

§Type Parameters
  • 'a: The lifetime of the values.
  • B: The break type.
  • C: The continue type.
  • C2: The output type for the Continue value.
  • B2: The output type for the Break value.
  • F: The applicative context.
§Parameters
  • cf: The control flow value.
  • f: The function for the Continue value.
  • g: The function for the Break value.
§Returns

The transformed control flow wrapped in the applicative context.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::brands::{
		ControlFlowBrand,
		OptionBrand,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
let y = ControlFlowBrand::bi_traverse::<_, _, _, _, OptionBrand>(
	x,
	|c| Some(c + 1),
	|b| Some(b * 2),
);
assert_eq!(y, Some(ControlFlow::Continue(4)));

Trait Implementations§

Source§

impl Bifoldable for ControlFlowBrand

Source§

fn bi_fold_right<'a, FnBrand: CloneFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a>( f: impl Fn(A, C) -> C + 'a, g: impl Fn(B, C) -> C + 'a, z: C, p: <Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> C

Folds the control flow from right to left using two step functions.

Applies f to the Continue value or g to the Break value.

§Type Signature

forall A B C. CloneFn FnBrand => ((A, C) -> C, (B, C) -> C, C, ControlFlow A B) -> C

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • C: The accumulator type.
§Parameters
  • f: The step function for the Continue variant.
  • g: The step function for the Break variant.
  • z: The initial accumulator.
  • p: The control flow to fold.
§Returns

The folded result.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	explicit::bi_fold_right::<RcFnBrand, ControlFlowBrand, _, _, _, _, _>(
		(|c, acc| acc - c, |b, acc| acc + b),
		10,
		x,
	),
	7
);
Source§

fn bi_fold_left<'a, FnBrand: CloneFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a>( f: impl Fn(C, A) -> C + 'a, g: impl Fn(C, B) -> C + 'a, z: C, p: <Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> C

Folds the control flow from left to right using two step functions.

Applies f to the Continue value or g to the Break value.

§Type Signature

forall A B C. CloneFn FnBrand => ((C, A) -> C, (C, B) -> C, C, ControlFlow A B) -> C

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • C: The accumulator type.
§Parameters
  • f: The step function for the Continue variant.
  • g: The step function for the Break variant.
  • z: The initial accumulator.
  • p: The control flow to fold.
§Returns

The folded result.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Break(5);
assert_eq!(
	explicit::bi_fold_left::<RcFnBrand, ControlFlowBrand, _, _, _, _, _>(
		(|acc, c| acc - c, |acc, b| acc + b),
		10,
		x,
	),
	15
);
Source§

fn bi_fold_map<'a, FnBrand: CloneFn + 'a, A: 'a + Clone, B: 'a + Clone, M>( f: impl Fn(A) -> M + 'a, g: impl Fn(B) -> M + 'a, p: <Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> M
where M: Monoid + 'a,

Maps the value to a monoid depending on the variant.

Applies f if Continue, g if Break.

§Type Signature

forall A B M. (CloneFn FnBrand, Monoid M) => (A -> M, B -> M, ControlFlow A B) -> M

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • M: The monoid type.
§Parameters
  • f: The function mapping the Continue value to the monoid.
  • g: The function mapping the Break value to the monoid.
  • p: The control flow to fold.
§Returns

The monoid value.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	explicit::bi_fold_map::<RcFnBrand, ControlFlowBrand, _, _, _, _, _>(
		(|c: i32| c.to_string(), |b: i32| b.to_string()),
		x,
	),
	"3".to_string()
);
Source§

impl Bifunctor for ControlFlowBrand

Source§

fn bimap<'a, A: 'a, B: 'a, C: 'a, D: 'a>( f: impl Fn(A) -> B + 'a, g: impl Fn(C) -> D + 'a, p: <Self as Kind_266801a817966495>::Of<'a, A, C>, ) -> <Self as Kind_266801a817966495>::Of<'a, B, D>

Maps functions over the values in the control flow.

This method applies one function to the continue value and another to the break value.

§Type Signature

forall A B C D. (A -> B, C -> D, ControlFlow A C) -> ControlFlow B D

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the continue value.
  • B: The type of the mapped continue value.
  • C: The type of the break value.
  • D: The type of the mapped break value.
§Parameters
  • f: The function to apply to the continue value.
  • g: The function to apply to the break value.
  • p: The control flow to map over.
§Returns

A new control flow containing the mapped values.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x = ControlFlow::<i32, i32>::Continue(1);
assert_eq!(
	explicit::bimap::<ControlFlowBrand, _, _, _, _, _, _>((|c| c + 1, |b: i32| b * 2), x),
	ControlFlow::Continue(2)
);
Source§

impl Bitraversable for ControlFlowBrand

Source§

fn bi_traverse<'a, A: 'a + Clone, B: 'a + Clone, C: 'a + Clone, D: 'a + Clone, F: Applicative>( f: impl Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, C> + 'a, g: impl Fn(B) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, D> + 'a, p: <Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_266801a817966495>::Of<'a, C, D>>

Traverses the control flow with two effectful functions.

Applies f to the Continue value or g to the Break value, wrapping the result in the applicative context.

§Type Signature

forall A B C D F. Applicative F => (A -> F C, B -> F D, ControlFlow A B) -> F (ControlFlow C D)

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • C: The output type for Continue.
  • D: The output type for Break.
  • F: The applicative context.
§Parameters
  • f: The function applied to the Continue value.
  • g: The function applied to the Break value.
  • p: The control flow to traverse.
§Returns

The transformed control flow wrapped in the applicative context.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	explicit::bi_traverse::<RcFnBrand, ControlFlowBrand, _, _, _, _, OptionBrand, _, _>(
		(|c: i32| Some(c + 1), |b: i32| Some(b * 2)),
		x,
	),
	Some(ControlFlow::Continue(4))
);
Source§

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

Sequences a bitraversable structure containing applicative values. Read more
Source§

impl Clone for ControlFlowBrand

Source§

fn clone(&self) -> ControlFlowBrand

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 Debug for ControlFlowBrand

Source§

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

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

impl Default for ControlFlowBrand

Source§

fn default() -> ControlFlowBrand

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

impl Hash for ControlFlowBrand

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 Kind_266801a817966495 for ControlFlowBrand

Generated implementation of Kind_266801a817966495 for ControlFlowBrand.

Source§

type Of<'a, C: 'a, B: 'a> = ControlFlow<B, C>

The applied type.
Source§

impl Kind_5b1bcedfd80bdc16 for ControlFlowBrand

Generated implementation of Kind_5b1bcedfd80bdc16 for ControlFlowBrand.

Source§

type Of<C, B> = ControlFlow<B, C>

The applied type.
Source§

impl Ord for ControlFlowBrand

Source§

fn cmp(&self, other: &ControlFlowBrand) -> 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 PartialEq for ControlFlowBrand

Source§

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

Source§

fn partial_cmp(&self, other: &ControlFlowBrand) -> 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 RefBifoldable for ControlFlowBrand

Source§

fn ref_bi_fold_right<'a, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a>( f: impl Fn(&A, C) -> C + 'a, g: impl Fn(&B, C) -> C + 'a, z: C, p: &<Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> C

Folds the control flow from right to left by reference using two step functions.

Applies f to a reference of the Continue value or g to a reference of the Break value, returning the folded result without consuming the control flow.

§Type Signature

forall A B C. LiftFn FnBrand => ((&A, C) -> C, (&B, C) -> C, C, &ControlFlow A B) -> C

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • C: The accumulator type.
§Parameters
  • f: The step function for a reference to the Continue variant.
  • g: The step function for a reference to the Break variant.
  • z: The initial accumulator.
  • p: The control flow to fold by reference.
§Returns

The folded result.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	explicit::bi_fold_right::<RcFnBrand, ControlFlowBrand, _, _, _, _, _>(
		(|c: &i32, acc| acc - *c, |b: &i32, acc| acc + *b),
		10,
		&x,
	),
	7
);

let y: ControlFlow<i32, i32> = ControlFlow::Break(5);
assert_eq!(
	explicit::bi_fold_right::<RcFnBrand, ControlFlowBrand, _, _, _, _, _>(
		(|c: &i32, acc| acc - *c, |b: &i32, acc| acc + *b),
		10,
		&y,
	),
	15
);
Source§

fn ref_bi_fold_left<'a, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a>( f: impl Fn(C, &A) -> C + 'a, g: impl Fn(C, &B) -> C + 'a, z: C, p: &<Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> C

Folds the bifoldable structure from left to right by reference using two step functions. Read more
Source§

fn ref_bi_fold_map<'a, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, M>( f: impl Fn(&A) -> M + 'a, g: impl Fn(&B) -> M + 'a, p: &<Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> M
where M: Monoid + 'a,

Maps elements of both types to a monoid by reference and combines the results. Read more
Source§

impl RefBifunctor for ControlFlowBrand

Source§

fn ref_bimap<'a, A: 'a, B: 'a, C: 'a, D: 'a>( f: impl Fn(&A) -> B + 'a, g: impl Fn(&C) -> D + 'a, p: &<Self as Kind_266801a817966495>::Of<'a, A, C>, ) -> <Self as Kind_266801a817966495>::Of<'a, B, D>

Maps functions over the values in the control flow by reference.

This method applies one function to a reference of the continue value and another to a reference of the break value, producing a new control flow with mapped values. The original control flow is borrowed, not consumed.

§Type Signature

forall A B C D. (&A -> B, &C -> D, &ControlFlow A C) -> ControlFlow B D

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the continue value.
  • B: The type of the mapped continue value.
  • C: The type of the break value.
  • D: The type of the mapped break value.
§Parameters
  • f: The function to apply to a reference of the continue value.
  • g: The function to apply to a reference of the break value.
  • p: The control flow to map over by reference.
§Returns

A new control flow containing the mapped values.

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		classes::ref_bifunctor::*,
		functions::*,
	},
};

let x = ControlFlow::<i32, i32>::Continue(1);
assert_eq!(
	ref_bimap::<ControlFlowBrand, _, _, _, _>(|c| *c + 1, |b: &i32| *b * 2, &x),
	ControlFlow::Continue(2)
);

let y = ControlFlow::<i32, i32>::Break(3);
assert_eq!(
	ref_bimap::<ControlFlowBrand, _, _, _, _>(|c| *c + 1, |b: &i32| *b * 2, &y),
	ControlFlow::Break(6)
);
Source§

impl RefBitraversable for ControlFlowBrand

Source§

fn ref_bi_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, C: 'a + Clone, D: 'a + Clone, F: Applicative>( f: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, C> + 'a, g: impl Fn(&B) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, D> + 'a, p: &<Self as Kind_266801a817966495>::Of<'a, A, B>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_266801a817966495>::Of<'a, C, D>>
where FnBrand: LiftFn + 'a, <Self as Kind_266801a817966495>::Of<'a, C, D>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, C>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, D>: Clone,

Traverses a control flow by reference with two effectful functions.

Applies f to a reference of the Continue value or g to a reference of the Break value, wrapping the result in the applicative context F.

§Type Signature

forall A B C D F. (Applicative F, LiftFn FnBrand) => (&A -> F C, &B -> F D, &ControlFlow A B) -> F (ControlFlow C D)

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function wrapper.
  • A: The type of the Continue value.
  • B: The type of the Break value.
  • C: The output type for Continue.
  • D: The output type for Break.
  • F: The applicative context.
§Parameters
  • f: The function applied to a reference of the Continue value.
  • g: The function applied to a reference of the Break value.
  • p: The control flow to traverse by reference.
§Returns

f(&a) wrapped in context for Continue(a), or g(&b) wrapped in context for Break(b).

§Examples
use {
	core::ops::ControlFlow,
	fp_library::{
		brands::*,
		functions::*,
	},
};

let x: ControlFlow<i32, i32> = ControlFlow::Continue(3);
assert_eq!(
	explicit::bi_traverse::<RcFnBrand, ControlFlowBrand, _, _, _, _, OptionBrand, _, _>(
		(|c: &i32| Some(c + 1), |b: &i32| Some(b * 2)),
		&x,
	),
	Some(ControlFlow::Continue(4))
);

let y: ControlFlow<i32, i32> = ControlFlow::Break(5);
assert_eq!(
	explicit::bi_traverse::<RcFnBrand, ControlFlowBrand, _, _, _, _, OptionBrand, _, _>(
		(|c: &i32| Some(c + 1), |b: &i32| Some(b * 2)),
		&y,
	),
	Some(ControlFlow::Break(10))
);
Source§

fn ref_bi_sequence<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>( ta: &<Self as Kind_266801a817966495>::Of<'a, <F as Kind_cdc7cd43dac7585f>::Of<'a, A>, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_266801a817966495>::Of<'a, A, B>>
where FnBrand: LiftFn + 'a, <Self as Kind_266801a817966495>::Of<'a, A, B>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Sequences a bitraversable structure containing applicative values by reference. Read more
Source§

impl Copy for ControlFlowBrand

Source§

impl Eq for ControlFlowBrand

Source§

impl StructuralPartialEq for ControlFlowBrand

Auto Trait Implementations§

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> Pipe for T

Source§

fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B

Pipes self into a function, enabling left-to-right composition. 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.