3 releases

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

#326 in Math

Download history 4/week @ 2024-09-19 4/week @ 2024-09-26 4/week @ 2024-10-10 4/week @ 2024-10-17 1/week @ 2024-10-31 2/week @ 2024-11-07 2/week @ 2024-11-14 1/week @ 2024-11-21 1/week @ 2024-12-05 3/week @ 2024-12-12 229/week @ 2024-12-26

232 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

~195KB