Module frunk::semigroup

source ·
Expand description

Module for holding the Semigroup typeclass definition and typeclass instances

You can, for example, combine tuples.

§Examples

use frunk::Semigroup;
use frunk_core::hlist;

let t1 = (1, 2.5f32, String::from("hi"), Some(3));
let t2 = (1, 2.5f32, String::from(" world"), None);

let expected = (2, 5.0f32, String::from("hi world"), Some(3));

assert_eq!(t1.combine(&t2), expected);

// ultimately, the Tuple-based Semigroup implementations are only available for a maximum of
// 26 elements. If you need more, use HList, which is has no such limit.

let h1 = hlist![1, 3.3, 53i64];
let h2 = hlist![2, 1.2, 1i64];
let h3 = hlist![3, 4.5, 54];
assert_eq!(h1.combine(&h2), h3)

Structs§

  • Wrapper type for boolean that acts as a bitwise && combination
  • Wrapper type for boolean that acts as a bitwise || combination
  • Wrapper type for types that are ordered and can have a Max combination
  • Wrapper type for types that are ordered and can have a Min combination
  • Wrapper type for types that can have a Product combination

Traits§

  • A Semigroup is a class of thing that has a definable combine operation

Functions§