https://github.com/grodowski/fnop
Weird attempt to use function composition for service objects
https://github.com/grodowski/fnop
Last synced: 10 months ago
JSON representation
Weird attempt to use function composition for service objects
- Host: GitHub
- URL: https://github.com/grodowski/fnop
- Owner: grodowski
- Created: 2020-04-01T09:01:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-01T09:02:31.000Z (almost 6 years ago)
- Last Synced: 2025-02-01T02:27:32.307Z (12 months ago)
- Language: Ruby
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Experiment with function composition
Create an operation with
```
operation = fnop do |context|
# do stuff
end
erroring_operation = fnop do |context|
context.stop('nope!')
end
```
Compose them with `>>` and run
```
composed =
operation >> erroring_operation >> operation
data = OpenStruct.new
res = composed.call(data)
res.error
=> 'nope!'
```
See `demo.rb` and `demo_spec.rb` for more examples.