deterministic 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/deterministic/either.rb +9 -0
- data/lib/deterministic/monad.rb +1 -1
- data/lib/deterministic/version.rb +1 -1
- data/spec/lib/deterministic/either/failure_spec.rb +34 -0
- data/spec/lib/deterministic/either/success_spec.rb +10 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53f5ad82104a1c379dd88c86c926bfb62ceca2e0
|
4
|
+
data.tar.gz: d7efc5de945b130c59a7005d182e263622d46815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9459fad3f2cb626638b2cdbe6838659c9d86306884df71b8a455c31be146f71e40bd5241d65cedd5c132ec1e4b13c090b231964e79ae03409d6a16cde23d3123
|
7
|
+
data.tar.gz: 7a04167f5f8856a7026e157cb20c4bbeebb5a669f0e5e8bc236ccc6efb1a7515a9abf0600bb7eef0821df414148b833f17e54dfbeb32c5d80e1a5dc7cdb55e69
|
data/README.md
CHANGED
@@ -8,6 +8,21 @@ This gem is still __WORK IN PROGRESS__.
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
+
### Success & Failure
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
Success(1).to_s # => "1"
|
15
|
+
Success(1) << Success(2) # => Success(2)
|
16
|
+
Success(Success(1)) # => Success(1)
|
17
|
+
Success(1).map { |v| v + 1} # => Success(2)
|
18
|
+
Success({a:1}).to_json # => '{"Success": {"a":1}}'
|
19
|
+
|
20
|
+
Failure(1).to_s # => "1"
|
21
|
+
Failure(1) << Failure(2) # => Failure(1)
|
22
|
+
Failure(Failure(1)) # => Failure(1)
|
23
|
+
Failure(1).map { |v| v + 1} # => Failure(2)
|
24
|
+
Failure({a:1}).to_json # => '{"Failure": {"a":1}}'
|
25
|
+
|
11
26
|
### Either#attempt_all
|
12
27
|
The basic idea is to execute a chain of units of work and make sure all return either `Success` or `Failure`.
|
13
28
|
|
data/lib/deterministic/either.rb
CHANGED
data/lib/deterministic/monad.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../monad_axioms'
|
3
|
+
|
4
|
+
include Deterministic
|
5
|
+
|
6
|
+
describe Deterministic::Failure do
|
7
|
+
|
8
|
+
it_behaves_like 'a Monad' do
|
9
|
+
let(:monad) { described_class }
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { described_class.new(1) }
|
13
|
+
|
14
|
+
specify { expect(subject).to be_an_instance_of described_class }
|
15
|
+
specify { expect(subject.value).to eq 1 }
|
16
|
+
specify { expect(subject).to be_failure }
|
17
|
+
specify { expect(subject).not_to be_success }
|
18
|
+
|
19
|
+
specify { expect(subject).to be_an_instance_of described_class }
|
20
|
+
specify { expect(subject).to eq(described_class.new(1)) }
|
21
|
+
specify { expect(subject << Success(2)).to eq(Failure(1)) }
|
22
|
+
specify { expect(subject << Failure(2)).to eq(Failure(1)) }
|
23
|
+
specify { expect(Failure(subject)).to eq Failure(1) }
|
24
|
+
specify { expect(subject.map { |v| v + 1} ).to eq Failure(2) }
|
25
|
+
|
26
|
+
it "#to_json" do
|
27
|
+
expect(Failure({a: 1}).to_json).to eq '{"Failure":{"a":1}}'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#to_s" do
|
31
|
+
expect(Failure(1).to_s).to eq "1"
|
32
|
+
expect(Failure({a: 1}).to_s).to eq "{:a=>1}"
|
33
|
+
end
|
34
|
+
end
|
@@ -5,7 +5,7 @@ include Deterministic
|
|
5
5
|
|
6
6
|
describe Deterministic::Success do
|
7
7
|
|
8
|
-
it_behaves_like 'a Monad' do
|
8
|
+
it_behaves_like 'a Monad' do
|
9
9
|
let(:monad) { described_class }
|
10
10
|
end
|
11
11
|
|
@@ -28,4 +28,13 @@ describe Deterministic::Success do
|
|
28
28
|
subject.bind { |v| true ? Success(v + 1) : Failure(v + 2)}
|
29
29
|
).to eq Success(2)
|
30
30
|
end
|
31
|
+
|
32
|
+
it "#to_json" do
|
33
|
+
expect(Success({a: 1}).to_json).to eq '{"Success":{"a":1}}'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#to_s" do
|
37
|
+
expect(Success(1).to_s).to eq "1"
|
38
|
+
expect(Success({a: 1}).to_s).to eq "{:a=>1}"
|
39
|
+
end
|
31
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deterministic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Zolnierek
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- spec/lib/deterministic/attempt_all_spec.rb
|
141
141
|
- spec/lib/deterministic/core_ext/either_spec.rb
|
142
142
|
- spec/lib/deterministic/core_ext/object/either_spec.rb
|
143
|
+
- spec/lib/deterministic/either/failure_spec.rb
|
143
144
|
- spec/lib/deterministic/either/match_spec.rb
|
144
145
|
- spec/lib/deterministic/either/success_spec.rb
|
145
146
|
- spec/lib/deterministic/either_spec.rb
|
@@ -177,6 +178,7 @@ test_files:
|
|
177
178
|
- spec/lib/deterministic/attempt_all_spec.rb
|
178
179
|
- spec/lib/deterministic/core_ext/either_spec.rb
|
179
180
|
- spec/lib/deterministic/core_ext/object/either_spec.rb
|
181
|
+
- spec/lib/deterministic/either/failure_spec.rb
|
180
182
|
- spec/lib/deterministic/either/match_spec.rb
|
181
183
|
- spec/lib/deterministic/either/success_spec.rb
|
182
184
|
- spec/lib/deterministic/either_spec.rb
|