Module frunk_core::hlist [] [src]

Module that holds HList data structures, implementations, and typeclasses.

Typically, you would want to use the hlist! macro to make it easier for you to use HList.

let h = hlist![1, "hi"];
assert_eq!(h.length(), 2);
let (a, b) = h.into_tuple2();
assert_eq!(a, 1);
assert_eq!(b, "hi");

// Reverse
let h1 = hlist![true, "hi"];
assert_eq!(h1.into_reverse(), hlist!["hi", true]);

// foldr (foldl also available)
let h2 = hlist![1, false, 42f32];
let folded = h2.foldr(
            hlist![
                |i, acc| i + acc,
                |_, acc| if acc > 42f32 { 9000 } else { 0 },
                |f, acc| f + acc
            ],
            1f32
    );
assert_eq!(folded, 9001);

// Mapping over an HList
let h3 = hlist![9000, "joe", 41f32];
let mapped = h3.map(hlist![
                        |n| n + 1,
                        |s| s,
                        |f| f + 1f32]);
assert_eq!(mapped, hlist![9001, "joe", 42f32]);

// Plucking a value out by type
let h4 = hlist![1, "hello", true, 42f32];
let (t, remainder): (bool, _) = h4.pluck();
assert!(t);
assert_eq!(remainder, hlist![1, "hello", 42f32]);

// Resculpting an HList
let h5 = hlist![9000, "joe", 41f32, true];
let (reshaped, remainder2): (Hlist![f32, i32, &str], _) = h5.sculpt();
assert_eq!(reshaped, hlist![41f32, 9000, "joe"]);
assert_eq!(remainder2, hlist![true]);Run

Structs

HCons

Represents the most basic non-empty HList. Its value is held in head while its tail is another HList.

HNil

Represents the right-most end of a heterogeneous list

There

Used as an index into an HList.

Enums

Here

Largely lifted from https://github.com/Sgeo/hlist/blob/master/src/lib.rs#L30 Used as an index into an HList.

Traits

HFoldLeftable

Left fold for a given data structure

HFoldRightable

Foldr for HLists

HList

Typeclass for HList-y behaviour

HMappable

Trail that allow for mapping over a data structure using mapping functions stored in another data structure

IntoReverse

Trait that allows for reversing a given data structure.

IntoTuple2

Trait for things that can be turned into a Tuple 2 (pair)

Plucker

Trait defining extraction from a given HList

Sculptor

An Sculptor trait, that allows us to extract/reshape/scult the current HList into another shape, provided that the requested shape's types are are contained within the current HList.

Selector

Trait for retrieving an HList element by type

Functions

h_cons

Takes an element and an Hlist and returns another one with the element prepended to the original list. The original list is consumed