Expand description
Functional programming type classes.
This module defines traits for common algebraic structures and functional abstractions,
such as Functor, Applicative and Monad.
Traits representing higher-kinded types (e.g., Functor) are implemented by
Brand types to simulate higher-kinded polymorphism, as Rust does not
natively support it.
§Examples
use fp_library::{brands::*, functions::*};
let x = Some(5);
let y = map::<OptionBrand, _, _, _>(|i| i * 2, x);
assert_eq!(y, Some(10));Re-exports§
pub use applicative::Applicative;pub use apply_first::ApplyFirst;pub use apply_second::ApplySecond;pub use bifunctor::Bifunctor;pub use category::Category;pub use cloneable_fn::CloneableFn;pub use compactable::Compactable;pub use defer::Defer;pub use filterable::Filterable;pub use foldable::Foldable;pub use function::Function;pub use functor::Functor;pub use lift::Lift;pub use monad::Monad;pub use monad_rec::MonadRec;pub use monoid::Monoid;pub use par_foldable::ParFoldable;pub use pointed::Pointed;pub use pointer::Pointer;pub use ref_counted_pointer::RefCountedPointer;pub use ref_functor::RefFunctor;pub use runnable::Runnable;pub use semiapplicative::Semiapplicative;pub use semigroup::Semigroup;pub use semigroupoid::Semigroupoid;pub use semimonad::Semimonad;pub use send_cloneable_fn::SendCloneableFn;pub use send_defer::SendDefer;pub use send_ref_counted_pointer::SendRefCountedPointer;pub use send_unsized_coercible::SendUnsizedCoercible;pub use traversable::Traversable;pub use unsized_coercible::UnsizedCoercible;pub use witherable::Witherable;
Modules§
- applicative
- A type class for applicative functors, allowing for values to be wrapped in a context and for functions within a context to be applied to values within a context.
- apply_
first - A type class for sequencing two computations and keeping the result of the first.
- apply_
second - A type class for sequencing two computations and keeping the result of the second.
- bifunctor
- A type class for types that can be mapped over two type arguments.
- category
- A type class for categories, which are semigroupoids with an identity element.
- cloneable_
fn - A trait for cloneable wrappers over closures, allowing for generic handling of cloneable functions in higher-kinded contexts.
- compactable
- A type class for data structures that can be compacted (filtering out
Nonevalues) and separated (splittingResultvalues). - defer
- A type class for types that can be constructed lazily.
- filterable
- A type class for data structures that can be filtered and partitioned.
- foldable
- A type class for data structures that can be folded to a single value.
- function
- A trait for wrappers over closures, allowing for generic handling of functions in higher-kinded contexts.
- functor
- A type class for types that can be mapped over.
- lift
- A type class for lifting binary functions into a context.
- monad
- A type class for monads, allowing for sequencing computations where the structure of the computation depends on the result of the previous computation.
- monad_
rec - A type class for monads that support stack-safe tail recursion.
- monoid
- A type class for types that have an identity element and an associative binary operation.
- par_
foldable - A type class for data structures that can be folded in parallel.
- pointed
- A type class for contexts that can be initialized with a value.
- pointer
- A hierarchy of traits for abstracting over different types of pointers, specifically focusing on reference-counted pointers (
Rc,Arc) and their capabilities. - ref_
counted_ pointer - A trait for reference-counted pointers with shared ownership.
- ref_
functor - A type class for types that can be mapped over, returning references.
- runnable
- A functor whose effects can be “run” to produce the inner value.
- semiapplicative
- A type class for applying functions within a context to values within a context.
- semigroup
- A type class for types that support an associative binary operation.
- semigroupoid
- A type class for semigroupoids, representing a set of objects and composable relationships between them.
- semimonad
- A type class for sequencing computations where the second computation depends on the result of the first.
- send_
cloneable_ fn - A trait for thread-safe cloneable wrappers over closures.
- send_
defer - A trait for deferred lazy evaluation with thread-safe thunks.
- send_
ref_ counted_ pointer - A trait for thread-safe reference-counted pointers.
- send_
unsized_ coercible - A trait for pointer brands that can coerce to thread-safe
dyn Fn + Send + Sync. - traversable
- A type class for data structures that can be traversed, accumulating results in an applicative context.
- unsized_
coercible - A trait for pointer brands that can perform unsized coercion to
dyn Fn. - witherable
- A type class for data structures that can be traversed and filtered in an applicative context.