try
try.cr 
Try monad for Crystal.
- crystal: 0.20.1
Usage
require "try"
i = Try(Int32) { 1 } # => Success(Int32)
i.map(&.+ 1).value # => 2
i = Try(Int32) { raise "error" } # => Failure(Int32)
i.map(&.+ 1).value # => Exception("error")
API
def success? : Bool
def failure? : Bool
def value : T
def get : T
def get? : T?
def failed : Try[Exception]
def foreach(&block : T -> U) : Nil
def map(&block : T -> U) : Try(U)
def flat_map(&block : T -> Try(U)) : Try(U)
def recover(&block : Exception -> U) : Try(U)
Installation
Add this to your application's shard.yml
:
dependencies:
try:
github: maiha/try.cr
Development
make test
Contributing
- Fork it ( https://github.com/maiha/try.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- maiha maiha - creator, maintainer