#frunk #generic #coproduct #labelled-generic #h-list

frunk_core

Frunk core provides developers with HList, Coproduct, LabelledGeneric and Generic

33 releases

0.4.1 Nov 3, 2022
0.4.0 Jun 25, 2021
0.3.2 Apr 16, 2021
0.3.1 Dec 21, 2019
0.0.11 Mar 22, 2017

#418 in Rust patterns

Download history 21379/week @ 2022-11-30 26045/week @ 2022-12-07 26894/week @ 2022-12-14 22547/week @ 2022-12-21 16792/week @ 2022-12-28 26090/week @ 2023-01-04 26651/week @ 2023-01-11 26156/week @ 2023-01-18 30546/week @ 2023-01-25 30668/week @ 2023-02-01 32508/week @ 2023-02-08 33080/week @ 2023-02-15 32180/week @ 2023-02-22 24522/week @ 2023-03-01 28907/week @ 2023-03-08 26615/week @ 2023-03-15

118,212 downloads per month
Used in 131 crates (31 directly)

MIT license

190KB
3K SLoC

Frunk Core

This library forms the core of Frunk. It should ideally be minimalistic, containing only the fundamental building blocks of generic programming.

Examples

# use frunk_core::hlist::*;
# use frunk_core::{hlist, HList};
# fn main() {

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

Links:

  1. Source on Github
  2. Crates.io page

Dependencies

~225KB