https://github.com/moba1/maybe
Crystal maybe monad
https://github.com/moba1/maybe
crystal crystal-lang crystal-language library
Last synced: 12 months ago
JSON representation
Crystal maybe monad
- Host: GitHub
- URL: https://github.com/moba1/maybe
- Owner: moba1
- License: mit
- Created: 2019-04-19T08:18:19.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-19T09:02:14.000Z (almost 7 years ago)
- Last Synced: 2025-02-05T21:57:54.159Z (about 1 year ago)
- Topics: crystal, crystal-lang, crystal-language, library
- Language: Crystal
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# maybe
Maybe Monad for Crystal
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
maybe:
github: moba1/maybe
```
2. Run `shards install`
## Usage
```crystal
require "maybe"
j = Maybe::Just.new(1)
p j.to_s # ==> Maybe::Just(Int32)(1)
p j.map { |x| x * 2 } # ==> Maybe::Just(Int32)(2)
p j.or_else(3) # ==> Maybe::Just(Int32)(1)
n = Maybe::Nothig(String).new # require type parameter in order to infer type
p n.to_s # ==> Maybe::Nothing(String)
p n.map { |x| x * 2 } # ==> Maybe::Nothing(Int32)
p n.or_else("Nothing!") # ==> Maybe::Just(String)("Nothing!")
```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Yuma Fukuda](https://github.com/moba1) - creator and maintainer