result
Version, currently 0.3.05 versions
- 0.4.0latestJul 13, 2020
- 0.3.1not indexedOct 15, 2020
- 0.3.0not indexedOct 15, 2020
- 0.2.0not indexedOct 15, 2020
- 0.1.0not indexedOct 15, 2020
github.com/anicholson/result.cr
Result monad for Crystal
10 stars
1 dependent
License: MIT
Nothing has been indexed for 0.3.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
result:
github: anicholson/result.cr
version: ~> 0.3.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.3.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
result.cr
Installation
Add this to your application's shard.yml:
dependencies:
result:
github: anicholson/result.cr
Usage
require "result/result"
struct Person
property first_name : String, last_name : String
def initialize(@first_name, @last_name)
end
end
alias PersonResult = Result(Person,String)
# wrapping values:
e = PersonResult.error("will cascade through")
v = PersonResult.ok(Person.new(first_name: "Erica", last_name: "Strange"))
e.is_a?(PersonResult) # => true
v.is_a?(PersonResult) # => true
# querying success
e.ok? # => false
v.ok? # => true
e.error? # => true
v.error? # => false
# unwrapping the Result
e.error # => "will cascade through" : String
v.value # => Person(@first_name:"Erica", @last_name:"Strange")
e.value # => raises ResultError
v.error # => raises ResultError
# chaining results
e.andThen {|r| v }.ok? # => false
e.orElse {|r| v }.ok? # => true
new_v = v.andThen {|r| r.first_name = "Tom"; PersonResult.ok(r) }
.andThen {|r| r.last_name = "Collins"; PersonResult.ok(r) }
new_v.ok? # => true
new_v.value # => Person(@first_name: "Tom", @last_name: "Collins")
v.andThen {|r| e }.ok? # => false
v.andThen {|r| e } == e # => true
Contributing
- Fork it ( https://github.com/anicholson/result.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
- anicholson Andy Nicholson - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.3.0- Tagged
- Oct 15, 2020
- Commit
ff8b75bfec2a- Indexed
- not yet
Dependents
Repository
github.com/anicholson/result.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Dec 1, 2026
- Synced
- Dec 1, 2026
- Versions
- 5