pub trait Functor<B>: Invariant<B> {
// Required method
fn map(self, f: impl FnMut(Self::Param) -> B) -> Self::Target<B>;
// Provided methods
fn fmap<F>(self, f: F) -> Self::Target<B>
where F: FnMut(Self::Param) -> B,
Self: Sized { ... }
fn fproduct<F>(self, f: F) -> Self::Target<(Self::Param, B)>
where F: FnMut(&Self::Param) -> B,
Self: Functor<(<Self as Higher>::Param, B)> + Sized { ... }
fn fproduct_left<F>(self, f: F) -> Self::Target<(B, Self::Param)>
where F: FnMut(&Self::Param) -> B,
Self: Functor<(B, <Self as Higher>::Param)> + Sized { ... }
fn map_const(self, b: B) -> Self::Target<B>
where B: Copy,
Self: Functor<B> + Sized { ... }
fn void(self) -> Self::Target<()>
where Self: Functor<(), Target<()> = <Self as Higher>::Target<B>> + Sized { ... }
fn tuple_left(self, b: B) -> Self::Target<(B, Self::Param)>
where B: Copy,
Self: Functor<(B, <Self as Higher>::Param)> + Sized { ... }
fn tuple_right(self, b: B) -> Self::Target<(Self::Param, B)>
where B: Copy,
Self: Functor<(<Self as Higher>::Param, B)> + Sized { ... }
fn unzip<A>(self) -> (Self::Target<A>, Self::Target<B>)
where Self: Higher<Param = (A, B)> + Functor<A> + Functor<B> + Copy + Sized { ... }
fn if_f<T, F>(self, if_true: T, if_false: F) -> Self::Target<B>
where T: FnMut() -> B,
F: FnMut() -> B,
Self: Functor<B, Param = bool> + Sized { ... }
}
Expand description
Covariant functor. See the module level documentation for more.
Required Methods§
Provided Methods§
sourcefn fmap<F>(self, f: F) -> Self::Target<B>where
F: FnMut(Self::Param) -> B,
Self: Sized,
fn fmap<F>(self, f: F) -> Self::Target<B>where F: FnMut(Self::Param) -> B, Self: Sized,
Alias for Functor::map if the implementing type already had a built-in .map
method.
sourcefn fproduct<F>(self, f: F) -> Self::Target<(Self::Param, B)>where
F: FnMut(&Self::Param) -> B,
Self: Functor<(<Self as Higher>::Param, B)> + Sized,
fn fproduct<F>(self, f: F) -> Self::Target<(Self::Param, B)>where F: FnMut(&Self::Param) -> B, Self: Functor<(<Self as Higher>::Param, B)> + Sized,
Tuple the values in Self<A>
with the result of applying a function with the value.
Examples
use rust2fun::prelude::*;
let x = Some(1);
let actual = x.fproduct(|x: &i32| x.to_string());
assert_eq!(Some((1, "1".to_string())), actual);
sourcefn fproduct_left<F>(self, f: F) -> Self::Target<(B, Self::Param)>where
F: FnMut(&Self::Param) -> B,
Self: Functor<(B, <Self as Higher>::Param)> + Sized,
fn fproduct_left<F>(self, f: F) -> Self::Target<(B, Self::Param)>where F: FnMut(&Self::Param) -> B, Self: Functor<(B, <Self as Higher>::Param)> + Sized,
Pair the result of function application with the values in Self<A>
.
Examples
use rust2fun::prelude::*;
let x = Some(1);
let actual = x.fproduct_left(|x: &i32| x.to_string());
assert_eq!(Some(("1".to_string(), 1)), actual);
sourcefn map_const(self, b: B) -> Self::Target<B>where
B: Copy,
Self: Functor<B> + Sized,
fn map_const(self, b: B) -> Self::Target<B>where B: Copy, Self: Functor<B> + Sized,
Replaces the A
value in Self<A>
with the supplied value.
Examples
use rust2fun::prelude::*;
let actual = Some(1).map_const("foo");
assert_eq!(Some("foo"), actual);
sourcefn void(self) -> Self::Target<()>where
Self: Functor<(), Target<()> = <Self as Higher>::Target<B>> + Sized,
fn void(self) -> Self::Target<()>where Self: Functor<(), Target<()> = <Self as Higher>::Target<B>> + Sized,
Empty the Self<A>
of the values, preserving the structure.
Examples
use rust2fun::prelude::*;
assert_eq!(Some(()), Some(1).void());
sourcefn tuple_left(self, b: B) -> Self::Target<(B, Self::Param)>where
B: Copy,
Self: Functor<(B, <Self as Higher>::Param)> + Sized,
fn tuple_left(self, b: B) -> Self::Target<(B, Self::Param)>where B: Copy, Self: Functor<(B, <Self as Higher>::Param)> + Sized,
Tuples the A
value in Self<A>
with the supplied B
value, with the B
value on the left.
Examples
use rust2fun::prelude::*;
assert_eq!(Some(("foo", 1)), Some(1).tuple_left("foo"));
sourcefn tuple_right(self, b: B) -> Self::Target<(Self::Param, B)>where
B: Copy,
Self: Functor<(<Self as Higher>::Param, B)> + Sized,
fn tuple_right(self, b: B) -> Self::Target<(Self::Param, B)>where B: Copy, Self: Functor<(<Self as Higher>::Param, B)> + Sized,
Tuples the A
value in Self<A>
with the supplied B
value, with the B
value on the right.
Examples
use rust2fun::prelude::*;
assert_eq!(Some((1, "foo")), Some(1).tuple_right("foo"));
sourcefn unzip<A>(self) -> (Self::Target<A>, Self::Target<B>)where
Self: Higher<Param = (A, B)> + Functor<A> + Functor<B> + Copy + Sized,
fn unzip<A>(self) -> (Self::Target<A>, Self::Target<B>)where Self: Higher<Param = (A, B)> + Functor<A> + Functor<B> + Copy + Sized,
Un-zips an Self<(A, B)>
consisting of element pairs into two separate Self’s tupled.
Examples
use rust2fun::prelude::*;
let x = Some((1, "foo"));
assert_eq!((Some(1), Some("foo")), Functor::unzip(x));