3 releases
0.1.2 | Dec 26, 2024 |
---|---|
0.1.1 | Dec 26, 2024 |
0.1.0 | Aug 20, 2024 |
#331 in Math
233 downloads per month
64KB
1.5K
SLoC
A monoid
A crate about monoids.
Example usage
use amonoid::{Monoid, from_ops::Add};
use std::num::Saturating;
fn braid<M: Monoid + Clone>(a: M, b: M, n: usize) -> M {
M::combine_iter([a, b].iter().cloned().cycle().take(2 * n))
}
assert_eq!(braid(Add(Saturating(2)), Add(Saturating(3)), 5), Add(Saturating(25)));
assert_eq!(braid("b".to_string(), "a".to_string(), 2), "baba");
lib.rs
:
A crate about monoids.
Crate Features
This crate supports the following feature flags, none of which are enabled by default:
num-traits
: Adds a dependency onnum_traits
to implementZero
forops::Additive
and [One
] forops::Multiplicative
.syn
: Adds a dependency on [syn
] to implementMonoid
forOption<
syn::Error
>
.graph-track-inconsistency
: Adds edge-case inconsistency detection tohom::graph::Graph
(seeGraph::input_mut
), at the cost of possibly increasing its size.
A note about equality
Some sections in the documentation use equality to state rules that must hold.
Strictly speaking, this would of course require the types in question to impl [Eq
].
However, since these requirements aren't enforced anyway,
it is up to the library consumer's discretion to ensure these on a "best effort" basis.
For example, you might want to consider f32
and f64
as monoids under addition or multiplication,
even tho they are very much non-associative in general, since they are approximately associative for "tame" inputs
(not too large and not too small).
Dependencies
~190KB