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.

Examples

#[macro_use]
extern crate frunk;

let h = hlist![1, "hi"];
assert_eq!(h.len(), 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![|acc, i| i + acc,
                   |acc, _| if acc > 42f32 { 9000 } else { 0 },
                   |acc, f| f + acc],
            1f32
    );
assert_eq!(folded, 9001);

let h3 = hlist![9000, "joe", 41f32];
// Mapping over an HList with a polymorphic function,
// declared using the poly_fn! macro (you can choose to impl
// it manually)
let mapped = h3.map(
  poly_fn![
    |f: f32|   -> f32 { f + 1f32 },
    |i: isize| -> isize { i + 1 },
    ['a] |s: &'a str| -> &'a str { s }
  ]);
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

Modules

foldr_owned

HFoldRightable inner mechanics for folding with a folder that needs to be owned.

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

Traits

HFoldLeftable

Trait for performing a left fold over an HList

HFoldRightable

Trait for performing a right fold over an HList

HList

Typeclass for HList-y behaviour

HMappable

Trait for mapping over an HList

HZippable

Trait for zipping HLists

IntoTuple2

Trait for transforming an HList into a nested tuple.

LiftFrom

Indexed type conversions of T -> Self with index I. This is a generalized version of From which for example allows the caller to use default values for parts of Self and thus “fill in the blanks”.

LiftInto

An indexed conversion that consumes self, and produces a T. To produce T, the index I may be used to for example “fill in the blanks”. LiftInto is the reciprocal of LiftFrom.

Plucker

Trait defining extraction from a given HList

Sculptor

Trait for pulling out some subset of an HList, using type inference.

Selector

Trait for borrowing 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

lift_from

Free function version of LiftFrom::lift_from.