3 releases

0.1.2 Dec 26, 2024
0.1.1 Dec 26, 2024
0.1.0 Aug 20, 2024

#331 in Math

Download history 1/week @ 2024-09-15 7/week @ 2024-09-22 1/week @ 2024-09-29 7/week @ 2024-10-13 1/week @ 2024-10-20 3/week @ 2024-11-03 3/week @ 2024-11-17 4/week @ 2024-12-08 214/week @ 2024-12-22 15/week @ 2024-12-29

233 downloads per month

MIT-0 license

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:

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