Skip to content

Commit

Permalink
Add Result#t
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloh committed Jun 27, 2024
1 parent 3720962 commit b9ca68a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/pathway/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit b9ca68a

Please sign in to comment.