Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/pjiwm/functional-rust
- Owner: Pjiwm
- License: mit
- Created: 2024-12-16T00:04:46.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-16T00:16:35.000Z (about 1 month ago)
- Last Synced: 2024-12-16T01:20:05.293Z (about 1 month ago)
- Topics: crate, currying, function, functional-programming, library, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
}