https://github.com/axect/fptools
Functional Programming and Efficient Tools for D
https://github.com/axect/fptools
Last synced: 9 months ago
JSON representation
Functional Programming and Efficient Tools for D
- Host: GitHub
- URL: https://github.com/axect/fptools
- Owner: Axect
- Created: 2018-09-12T04:58:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-14T15:56:27.000Z (over 7 years ago)
- Last Synced: 2025-03-22T23:58:34.486Z (9 months ago)
- Language: D
- Size: 3.31 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FPTools
Functional Programming & Efficient Tools for D.
## Why FPTools?
In Rust, we can use functional programming anywhere because same speed is guaranteed by zero cost abstraction.
But in D, we can find functional programming is much slower than OOP or procedural programming.
In FPTools, it is also guaranteed like Rust by hand written functions.
## Usage
### Add Dependency
* Add `dependencies` in `dub.json`
```json
// In dub.json
{
"dependencies": {
"fptools": "~>0.0.2"
},
}
```
### Example
```d
import dtools.fp;
void main() {
mixin FP!long; // You can choose any type to use FP (double, string, int, long and etc.)
Pipe p; // Declare pipeline
p.input(seq(1,100)); // Input sequence
p.proc( // Write Procedures
map(x => 2 * x), // map (Haskell like)
takeWhile(x => x < 100), // takeWhile (Haskell like)
map(x => x / 2), // map (Haskell like)
take(40), // take (Haskell like)
drop(10), // drop (Haskell like)
dropWhile(x => x < 30), // dropWhile (Haskell like)
reduce((x,y) => x * y) // reduce (Haskell like)
);
p.output[0].writeln; // output function exports result as sequence
}
```