Releases: dry-rb/dry-monads
v1.8.3
v1.8.2
v1.8.1
Fixed
- Exclude extensions from the Zeitwerk loader (fix #185) (@flash-gordon)
v1.8.0
Added
-
New extension for RSpec (@flash-gordon in #183):
One of the pain points of testing monads is referencing class constants from specs.
This extension catches missing class constants, analyzes the call site and
returns a matching constant.Before, this code would raise a
NameError
becauseFailure
is a constant
that is missing inObject
:example "missing constant" do expect(call_operation).to eql(Failure[:some_error, "some message"]) end
Now, after enabling the extension, it will return the correct constant:
Dry::Monads.load_extensions(:rspec) example "missing constant" do Failure[:some_error, "some message"] # => Failure[:some_error, "some message"] end
Out of the box, the extension will check if
Success
,Failure
,Some
, and
None
are referenced from a file ending with_spec.rb
.More involved analysis is possible if you add
debug_inspector
to your Gemfile:group :test do gem "debug_inspector" end
This will allow referencing constants from other modules, such as rspec helpers.
The extension also adds new matchers for
Success
,Failure
,Some
, and
None
values.expect(Success(1)).to be_success expect(Success(1)).to be_success(1) expect(Success(1)).to be_success { |x| x > 0 } expect(Success(1)).to be_a_success { |x| x > 0 } expect(Failure(1)).to be_failure(1) expect(Some(1)).to be_some expect(Some(1)).to be_success expect(None()).to be_none expect(None()).to be_failure
-
New extension for super_diff (@flash-gordon in #184):
Adds support for improved diff output in specs when using the super_diff gem.
This makes it easier to understand the differences between monad values in test failures.To use this extension:
- Add super_diff to your Gemfile's test group:
group :test do gem "super_diff" end
- Load the extension:
require "dry/monads" Dry::Monads.load_extensions(:super_diff)
This will change the diff output for monad values to be more readable.
Before:
-Success({a: 2, c: 2}) +Success({a: 1, b: 2})
After:
Success( - a: 2, + a: 1, - c: 2 + b: 2 )
- Add super_diff to your Gemfile's test group:
v1.7.1
v1.7.0
Fixed
- Fix pattern matching for
Try
values (@alexkalderimis)
Changed
- Set 3.1 as minimum Ruby version (@flash-gordon)
v1.6.0
v1.5.0
Changed
- Use zeitwerk for auto-loading dry-monads classes (@flash-gordon)
Task#then
is deprecated in favor ofTask#bind
(@flash-gordon)- Minimal Ruby version is now 2.7 (@flash-gordon)
- Either (old name of Result) was removed (@flash-gordon)
v1.4.0
Added
Unit
destructures to an empty array (flash-gordon)- When
.value!
called on aFailure
value the error references to the value (rewritten + flash-gordon)begin Failure("oops").value! rescue => error error.receiver # => Failure("oops") end
Result#alt_map
for mapping failure values (flash-gordon)Failure("oops").alt_map(&:upcase) # => Failure("OOPS")
Try#recover
recovers from errors (flash-gordon)error = Try { Hash.new.fetch(:missing) } error.recover(KeyError) { 'default' } # => Try::Value("default")
Maybe#filter
runs a predicate against the wrapped value. ReturnsNone
if the result is false (flash-gordon)Some(3).filter(&:odd?) # => Some(3) Some(3).filter(&:even?) # => None # no block given Some(3 == 5).filter # => None
RightBiased#|
is an alias for#or
(flash-gordon)None() | Some(6) | Some(7) # => Some(6) Failure() | Success("one") | Success("two") # => Success("one")
Fixed
- Do notation preserves method visibility (anicholson + flash-gordon)
Changed
- Coercing
nil
values toNone
withSome#fmap
is officially deprecated. (flash-gordon)
Switch toSome#maybe
when you expectnil
.
This behavior will be dropped in 2.0 but you can opt-out of warnings for the time beingDry::Monads::Maybe.warn_on_implicit_nil_coercion false
- Minimal Ruby version is 2.6