From b9ca68a5df94390fd56f9a47a75a74d31661d786 Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Thu, 27 Jun 2024 02:15:16 -0300 Subject: [PATCH] Add Result#t --- CHANGELOG.md | 4 ++++ lib/pathway/result.rb | 1 + spec/result_spec.rb | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 427b212..79b6816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.12.2] - 2024-06-27 +### Added +- Add `Result#t` shorthand alias for "Result#then" + ## [0.12.1] - 2024-06-23 ### Added - Add support for pattern matching on `Result`, `State` and `Error` instances diff --git a/lib/pathway/result.rb b/lib/pathway/result.rb index b32f0d9..04e2824 100644 --- a/lib/pathway/result.rb +++ b/lib/pathway/result.rb @@ -4,6 +4,7 @@ module Pathway class Result extend Forwardable attr_reader :value, :error + def_delegator :self, :then, :t class Success < Result def initialize(value) diff --git a/spec/result_spec.rb b/spec/result_spec.rb index c229086..0967181 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -49,6 +49,13 @@ module Pathway it { expect(prev_result.failure?).to be false } end + describe "#t" do + it "aliases the correct submethod" do + expect(prev_result.t{ |prev| "ALIASED " + prev }) + .to be_a(Result::Success).and(have_attributes(value: "ALIASED VALUE")) + end + end + describe "#then" do let(:callable) { double } let(:next_result) { Result.success("NEW VALUE")} @@ -108,6 +115,12 @@ module Pathway end end + describe "#t" do + it "aliases the correct submethod" do + expect(prev_result.t{ |prev| "ALIASED " + prev }).to eq(prev_result) + end + end + describe "#then" do let(:callable) { double } before { expect(callable).to_not receive(:call) }