Crate frunk_core
source ·Expand description
Frunk Core
This library forms the core of Frunk. It should ideally be minimalistic, containing only the fundamental building blocks of generic programming.
Examples
let h = hlist![1, false, 42f32];
let folded = h.foldr(hlist![|i, acc| i + acc,
|_, acc| if acc > 42f32 { 9000 } else { 0 },
|f, acc| f + acc],
1f32);
assert_eq!(folded, 9001);
// 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.to_ref().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]);
RunLinks:
Modules
Module that holds Coproduct data structures, traits, and implementations
This module holds the machinery behind
Generic
.Module that holds HList data structures, implementations, and typeclasses.
Types used for indexing into HLists and coproducts.
This module holds the machinery behind LabelledGeneric.
Traits that provide generic functionality for multiple types in frunk
Macros
Returns a type signature for a Coproduct of the provided types
Returns a type signature for an HList of the provided types
Used for creating a Field
Returns an
HList
based on the values passed in.Macro for pattern-matching on HLists.
Returns a polymorphic function for use with mapping/folding heterogeneous
types.