use fp_macros::*;
pub use crate::{
classes::{
alternative::guard,
applicative::{
unless,
when,
},
bitraversable::{
bi_for,
bi_sequence,
for_left,
for_right,
traverse_left,
traverse_right,
},
category::identity as category_identity,
clone_fn::new as lift_fn_new,
clone_fn::ref_new as ref_lift_fn_new,
deferrable::defer,
division_ring::{
divide_left,
divide_right,
reciprocate,
},
euclidean_ring::{
degree,
divide,
gcd,
lcm,
modulo,
},
extend::{
compose_co_kleisli,
compose_co_kleisli_flipped,
duplicate,
extend,
extend_flipped,
},
extract::extract,
heyting_algebra::{
conjoin,
disjoin,
false_value,
imply,
not,
true_value,
},
monad::{
if_m,
unless_m,
when_m,
},
monad_rec::{
forever,
repeat_m,
tail_rec_m,
until_m,
until_some,
while_m,
while_some,
},
monoid::{
empty,
power,
},
par_compactable::{
par_compact,
par_separate,
},
par_filterable::{
par_filter,
par_filter_map,
},
par_filterable_with_index::{
par_filter_map_with_index,
par_filter_with_index,
},
par_foldable::par_fold_map,
par_foldable_with_index::par_fold_map_with_index,
par_functor::par_map,
par_functor_with_index::par_map_with_index,
par_ref_filterable::{
par_ref_filter,
par_ref_filter_map,
},
par_ref_filterable_with_index::{
par_ref_filter_map_with_index,
par_ref_filter_with_index,
},
par_ref_foldable::par_ref_fold_map,
par_ref_foldable_with_index::par_ref_fold_map_with_index,
par_ref_functor::par_ref_map,
par_ref_functor_with_index::par_ref_map_with_index,
pipe::pipe,
plus::empty as plus_empty,
pointed::pure,
pointer::new as pointer_new,
profunctor::{
arrow,
dimap,
map_input,
map_output,
},
ref_bitraversable::{
ref_bi_for,
ref_bi_for_left,
ref_bi_for_right,
ref_bi_sequence,
ref_bi_traverse_left,
ref_bi_traverse_right,
},
ref_counted_pointer::new as ref_counted_pointer_new,
ref_counted_pointer::{
take_cell_new,
take_cell_take,
try_unwrap,
},
ref_monad::{
ref_if_m,
ref_unless_m,
},
ref_pointed::ref_pure,
ref_semiapplicative::ref_apply,
ref_traversable::ref_traverse,
ring::{
negate,
subtract,
},
semigroup::append,
semigroupoid::compose as semigroupoid_compose,
semiring::{
add,
multiply,
one,
zero,
},
send_clone_fn::new as send_lift_fn_new,
send_clone_fn::ref_new as send_ref_lift_fn_new,
send_deferrable::send_defer,
send_ref_apply_first::send_ref_apply_first,
send_ref_apply_second::send_ref_apply_second,
send_ref_counted_pointer::new as send_ref_counted_pointer_new,
send_ref_foldable::send_ref_fold_map,
send_ref_foldable_with_index::send_ref_fold_map_with_index,
send_ref_functor::send_ref_map,
send_ref_functor_with_index::send_ref_map_with_index,
send_ref_lift::send_ref_lift2,
send_ref_pointed::send_ref_pure,
send_ref_semiapplicative::send_ref_apply,
send_ref_semimonad::send_ref_bind,
to_dyn_clone_fn::new as to_dyn_clone_fn,
to_dyn_clone_fn::ref_new as to_ref_dyn_clone_fn,
to_dyn_fn::to_dyn_fn,
to_dyn_fn::to_ref_dyn_fn,
to_dyn_send_fn::new as to_dyn_send_fn,
to_dyn_send_fn::ref_new as to_ref_dyn_send_fn,
traversable::sequence,
},
dispatch::{
alt::alt,
apply_first::apply_first,
apply_second::apply_second,
bifoldable::{
bi_fold_left,
bi_fold_map,
bi_fold_right,
},
bifunctor::bimap,
bitraversable::bi_traverse,
compactable::{
compact,
separate,
},
contravariant::contramap,
filterable::{
filter,
filter_map,
partition,
partition_map,
},
filterable_with_index::{
filter_map_with_index,
filter_with_index,
partition_map_with_index,
partition_with_index,
},
foldable::{
fold_left,
fold_map,
fold_right,
},
foldable_with_index::{
fold_left_with_index,
fold_map_with_index,
fold_right_with_index,
},
functor::map,
functor_with_index::map_with_index,
lift::{
lift2,
lift3,
lift4,
lift5,
},
map_first::map_first,
map_second::map_second,
semiapplicative::apply,
semimonad::{
bind,
bind_flipped,
compose_kleisli,
compose_kleisli_flipped,
join,
},
traversable::traverse,
traversable_with_index::traverse_with_index,
witherable::{
wilt,
wither,
},
},
types::{
lazy::{
arc_lazy_fix,
rc_lazy_fix,
},
optics::{
optics_as_index,
optics_compose,
optics_indexed_fold_map,
optics_indexed_over,
optics_indexed_preview,
optics_indexed_set,
optics_indexed_view,
optics_reindexed,
optics_un_index,
positions,
},
},
};
pub mod explicit {
pub use crate::{
classes::semiapplicative::apply,
dispatch::{
alt::explicit::alt,
apply_first::explicit::apply_first,
apply_second::explicit::apply_second,
bifoldable::explicit::{
bi_fold_left,
bi_fold_map,
bi_fold_right,
},
bifunctor::explicit::bimap,
bitraversable::explicit::bi_traverse,
compactable::explicit::{
compact,
separate,
},
contravariant::explicit::contramap,
filterable::explicit::{
filter,
filter_map,
partition,
partition_map,
},
filterable_with_index::explicit::{
filter_map_with_index,
filter_with_index,
partition_map_with_index,
partition_with_index,
},
foldable::explicit::{
fold_left,
fold_map,
fold_right,
},
foldable_with_index::explicit::{
fold_left_with_index,
fold_map_with_index,
fold_right_with_index,
},
functor::explicit::map,
functor_with_index::explicit::map_with_index,
lift::explicit::{
lift2,
lift3,
lift4,
lift5,
},
map_first::explicit::map_first,
map_second::explicit::map_second,
semimonad::explicit::{
bind,
bind_flipped,
join,
},
traversable::explicit::traverse,
traversable_with_index::explicit::traverse_with_index,
witherable::explicit::{
wilt,
wither,
},
},
};
}
#[document_signature]
#[document_type_parameters(
"The input type of the inner function `g`.",
"The output type of `g` and the input type of `f`.",
"The output type of the outer function `f`."
)]
#[document_parameters(
"The outer function to apply second.",
"The inner function to apply first.",
"The argument to be passed to the composed function."
)]
pub fn compose<A, B, C>(
f: impl Fn(B) -> C,
g: impl Fn(A) -> B,
) -> impl Fn(A) -> C {
move |a| f(g(a))
}
#[document_signature]
#[document_type_parameters(
"The type of the value to return.",
"The type of the argument to ignore."
)]
#[document_parameters(
"The value to be returned by the constant function.",
"The argument to be ignored."
)]
pub fn constant<A: Clone, B>(
a: A,
_b: B,
) -> A {
a
}
#[document_signature]
#[document_type_parameters(
"The type of the first argument of the input function.",
"The type of the second argument of the input function.",
"The return type of the function."
)]
#[document_parameters(
"A binary function.",
"The second argument (which will be passed as the first to `f`).",
"The first argument (which will be passed as the second to `f`)."
)]
pub fn flip<A, B, C>(f: impl Fn(A, B) -> C) -> impl Fn(B, A) -> C {
move |b, a| f(a, b)
}
#[document_signature]
#[document_type_parameters("The type of the value.")]
#[document_parameters("A value.")]
pub fn identity<A>(a: A) -> A {
a
}
#[document_signature]
#[document_type_parameters(
"The type of the original arguments.",
"The type of the projected arguments.",
"The result type."
)]
#[document_parameters(
"The binary function to apply to the projected values.",
"The projection function applied to both arguments.",
"The first argument.",
"The second argument."
)]
#[document_returns("The result of applying `f` to the projected values.")]
#[document_examples]
pub fn on<A, B, C>(
f: impl Fn(B, B) -> C,
g: impl Fn(A) -> B,
x: A,
y: A,
) -> C {
f(g(x), g(y))
}