Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pjiwm/functional-rust

A Rust library for functional programming, providing function composition, currying, and higher-order functions. This crate can be compiled on nightly Rust.
https://github.com/pjiwm/functional-rust

crate currying function functional-programming library rust rust-lang

Last synced: about 1 month ago
JSON representation

A Rust library for functional programming, providing function composition, currying, and higher-order functions. This crate can be compiled on nightly Rust.

Awesome Lists containing this project

README

        

# functional_rs
`functional_rs` is an experimental crate that brings functional programming concepts to Rust using Nightly features.
By implementing `Fn` on structs, it enables function composition, currying, and other higher-order functional programming patterns.
The goal is to keep the syntax as concise as possible, making functional patterns easy to use without cluttering the code.

This crate is designed for **Nightly Rust** and uses experimental features, so it’s not stable yet.

## Example

```rust
use functional_rs::{c, f, ComposableFn};
use std::str::FromStr;

fn main() {
let from_str = i32::from_str;
let parse_or_zero = |result: Result::Err>| result.unwrap_or(0);

// Currying with composition
let add = c!(|a: i32, b: i32| a + b);
let add_10_from_str = f!(from_str) >> f!(parse_or_zero) >> f!(add(10));

// Using the composed function
assert_eq!(add_10_from_str("4"), 14); // (4 -> parse -> add 10) = 14
assert_eq!(add_10_from_str("not a number"), 10); // invalid input -> default 10
}