1 unstable release
0.1.0 | Mar 1, 2025 |
---|
#1451 in Rust patterns
152 downloads per month
11KB
261 lines
rusty-hkt
A lightweight, no_std compatible library for emulating higher-kinded types in Rust.
Overview
rusty-hkt
provides traits and implementations that enable functional programming patterns requiring higher-kinded types, which are not natively supported in Rust's type system.
The library uses a trait-based approach to emulate higher-kinded types, allowing you to write generic code over type constructors such as Option
, Result
, Vec
, and others.
Features
- No standard library requirement: Works in
no_std
environments - Functional abstractions: Includes
Functor
,Applicative
, andMonad
traits - Built-in implementations for common Rust types:
Option
Result
Vec
(requires thealloc
feature)Box
(requires thealloc
feature)Identity
(a simple wrapper type)
- Zero dependencies beyond the Rust core library
Usage
Add this to your Cargo.toml
:
[dependencies]
rusty-hkt = "0.1.0"
Basic Example
use rusty_hkt::{Functor, OptionHKT, map};
fn main() {
let opt = Some(3);
let doubled = map::<OptionHKT, _, _, _>(opt, |x| x * 2);
assert_eq!(doubled, Some(6));
}
Working with Generic Type Constructors
use rusty_hkt::{Functor, HKT};
// A function that works with any Functor
fn double_inside<F: Functor, A>(fa: F::Applied<A>) -> F::Applied<A>
where
A: std::ops::Mul<Output = A> + Copy,
{
F::map(fa, |x| x * x)
}
// Can be used with Option, Result, Vec, etc.
License
Licensed under the Apache License, Version 2.0. See the LICENSE file for more info.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Contact
- GitHub: voltageddebunked
- Email: rusindanilo@gmail.com