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.
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:
ControlFlowBrand: fully polymorphic over both continue and break types (bifunctor).ControlFlowContinueAppliedBrand<C>: the continue type is fixed, polymorphic over the break type (functor over break).ControlFlowBreakAppliedBrand<B>: the break type is fixed, polymorphic over the continue type (functor over continue).
Sourcepub fn is_continue<B, C>(cf: &ControlFlow<B, C>) -> bool
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));Sourcepub fn is_break<B, C>(cf: &ControlFlow<B, C>) -> bool
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));Sourcepub fn map_continue<B, C, C2>(
cf: ControlFlow<B, C>,
f: impl FnOnce(C) -> C2,
) -> ControlFlow<B, C2>
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));Sourcepub fn map_break<B, C, B2>(
cf: ControlFlow<B, C>,
f: impl FnOnce(B) -> B2,
) -> ControlFlow<B2, C>
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));Sourcepub fn bimap<B, C, B2, C2>(
cf: ControlFlow<B, C>,
f: impl FnOnce(C) -> C2,
g: impl FnOnce(B) -> B2,
) -> ControlFlow<B2, C2>
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));Sourcepub 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
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);Sourcepub 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
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);Sourcepub fn bi_fold_map<B, C, M>(
cf: ControlFlow<B, C>,
f: impl FnOnce(C) -> M,
g: impl FnOnce(B) -> M,
) -> M
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"
);Sourcepub fn fold_right<B, C, Acc>(
cf: ControlFlow<B, C>,
f: impl FnOnce(B, Acc) -> Acc,
initial: Acc,
) -> Acc
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);Sourcepub fn fold_left<B, C, Acc>(
cf: ControlFlow<B, C>,
f: impl FnOnce(Acc, B) -> Acc,
initial: Acc,
) -> Acc
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);Sourcepub fn fold_map<B, C, M: Monoid>(
cf: ControlFlow<B, C>,
f: impl FnOnce(B) -> M,
) -> M
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());Sourcepub fn bind_break<B, C, B2>(
cf: ControlFlow<B, C>,
f: impl FnOnce(B) -> ControlFlow<B2, C>,
) -> ControlFlow<B2, C>
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));Sourcepub fn bind_continue<B, C, C2>(
cf: ControlFlow<B, C>,
f: impl FnOnce(C) -> ControlFlow<B, C2>,
) -> ControlFlow<B, C2>
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));Sourcepub fn break_val<B, C>(cf: ControlFlow<B, C>) -> Option<B>
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);Sourcepub fn continue_val<B, C>(cf: ControlFlow<B, C>) -> Option<C>
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);Sourcepub fn swap<B, C>(cf: ControlFlow<B, C>) -> ControlFlow<C, B>
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"));Sourcepub 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,
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
impl Bifoldable for ControlFlowBrand
Source§fn bi_fold_right<'a, FnBrand: CloneableFn + '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
fn bi_fold_right<'a, FnBrand: CloneableFn + '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. ((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!(
bi_fold_right::<RcFnBrand, ControlFlowBrand, _, _, _>(
|c, acc| acc - c,
|b, acc| acc + b,
10,
x,
),
7
);Source§fn bi_fold_left<'a, FnBrand: CloneableFn + '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
fn bi_fold_left<'a, FnBrand: CloneableFn + '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. ((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!(
bi_fold_left::<RcFnBrand, ControlFlowBrand, _, _, _>(
|acc, c| acc - c,
|acc, b| acc + b,
10,
x,
),
15
);Source§fn bi_fold_map<'a, FnBrand: CloneableFn + '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>,
) -> Mwhere
M: Monoid + 'a,
fn bi_fold_map<'a, FnBrand: CloneableFn + '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>,
) -> Mwhere
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. 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!(
bi_fold_map::<RcFnBrand, ControlFlowBrand, _, _, _>(
|c: i32| c.to_string(),
|b: i32| b.to_string(),
x,
),
"3".to_string()
);Source§impl Bifunctor for ControlFlowBrand
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>
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::*,
classes::bifunctor::*,
functions::*,
},
};
let x = ControlFlow::<i32, i32>::Continue(1);
assert_eq!(
bimap::<ControlFlowBrand, _, _, _, _>(|c| c + 1, |b: i32| b * 2, x),
ControlFlow::Continue(2)
);Source§impl Bitraversable for ControlFlowBrand
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>>
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!(
bi_traverse::<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,
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,
Source§impl Clone for ControlFlowBrand
impl Clone for ControlFlowBrand
Source§fn clone(&self) -> ControlFlowBrand
fn clone(&self) -> ControlFlowBrand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ControlFlowBrand
impl Debug for ControlFlowBrand
Source§impl Default for ControlFlowBrand
impl Default for ControlFlowBrand
Source§fn default() -> ControlFlowBrand
fn default() -> ControlFlowBrand
Source§impl Hash for ControlFlowBrand
impl Hash for ControlFlowBrand
Source§impl Kind_266801a817966495 for ControlFlowBrand
Generated implementation of Kind_266801a817966495 for ControlFlowBrand.
impl Kind_266801a817966495 for ControlFlowBrand
Generated implementation of Kind_266801a817966495 for ControlFlowBrand.
Source§type Of<'a, C: 'a, B: 'a> = ControlFlow<B, C>
type Of<'a, C: 'a, B: 'a> = ControlFlow<B, C>
Source§impl Kind_5b1bcedfd80bdc16 for ControlFlowBrand
Generated implementation of Kind_5b1bcedfd80bdc16 for ControlFlowBrand.
impl Kind_5b1bcedfd80bdc16 for ControlFlowBrand
Generated implementation of Kind_5b1bcedfd80bdc16 for ControlFlowBrand.
Source§type Of<C, B> = ControlFlow<B, C>
type Of<C, B> = ControlFlow<B, C>
Source§impl Ord for ControlFlowBrand
impl Ord for ControlFlowBrand
Source§fn cmp(&self, other: &ControlFlowBrand) -> Ordering
fn cmp(&self, other: &ControlFlowBrand) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ControlFlowBrand
impl PartialEq for ControlFlowBrand
Source§impl PartialOrd for ControlFlowBrand
impl PartialOrd for ControlFlowBrand
impl Copy for ControlFlowBrand
impl Eq for ControlFlowBrand
impl StructuralPartialEq for ControlFlowBrand
Auto Trait Implementations§
impl Freeze for ControlFlowBrand
impl RefUnwindSafe for ControlFlowBrand
impl Send for ControlFlowBrand
impl Sync for ControlFlowBrand
impl Unpin for ControlFlowBrand
impl UnsafeUnpin for ControlFlowBrand
impl UnwindSafe for ControlFlowBrand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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