Module classes

Module classes 

Source
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 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 monoid::Monoid;
pub use once::Once;
pub use par_foldable::ParFoldable;
pub use pointed::Pointed;
pub use pointer::Pointer;
pub use ref_counted_pointer::RefCountedPointer;
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 thunk_wrapper::ThunkWrapper;
pub use traversable::Traversable;
pub use try_monoid::TryMonoid;
pub use try_semigroup::TrySemigroup;
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.
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 None values) and separated (splitting Result values).
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.
monoid
A type class for types that have an identity element and an associative binary operation.
once
A type class for containers that hold a value that is initialized at most once.
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.
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.
thunk_wrapper
A trait for pointers that can wrap a thunk with interior mutability.
traversable
A type class for data structures that can be traversed, accumulating results in an applicative context.
try_monoid
A trait for types that can be combined fallibly and have an empty value.
try_semigroup
A trait for types that can be combined fallibly.
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.