deterministic 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a2ce59cd264bdbafaa4a86660553c4e407b6607
4
- data.tar.gz: d3418defe22825466d5c4bdb7c7363f53c767442
3
+ metadata.gz: a8e5d5bcf60bb0a88e48107853dbc0b38aa0495b
4
+ data.tar.gz: b319c46c0356abc592203b5d364c5f033bc90045
5
5
  SHA512:
6
- metadata.gz: 6226df9e5bef50b905208606a0634aa94b8ca70d61be98318a02ffe6da40bb90ddec4304b6ccfa0a844d5230ab9743d25fa9997c65e5fc64e378e9505e45f08f
7
- data.tar.gz: 6b3d7eeb06e263853cdad760a5df74043981f914be4e69ed80b10c37618ce1d6e9134e01a65675ce305d2fc6fa15b7c380dbf3cc760902769f6c9ba1e8e8e227
6
+ metadata.gz: 90736736f45c37196aa250de61a38a43d5e1c4d58c9fa517d0f7a96cb31a7e3596d647d01c4ac3946829204bed5164d360bb0257620417b7fb71543c20c0d77f
7
+ data.tar.gz: 04e675507417f1af47fcdeb4ababb511b665b320ee570780ff204e88482f6fe5bab16b087212a9222d783a1f12add100fac74c22d21f833f8617c83806d30877
data/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/deterministic.png)](http://badge.fury.io/rb/deterministic)
4
4
 
5
+ Deterministic is to help your code to be more confident, it's specialty is flow control of actions that either succeed or fail.
6
+
5
7
  This is a spiritual successor of the [Monadic gem](http://github.com/pzol/monadic). The goal of the rewrite is to get away from a bit to forceful aproach I took in Monadic, especially when it comes to coercing monads, but also a more practical but at the same time more strict adherence to monad laws.
6
8
 
7
- This gem is still __WORK IN PROGRESS__.
8
9
 
9
10
  ## Usage
10
11
 
@@ -24,6 +25,30 @@ Failure(1).map { |v| v + 1} # => Failure(2)
24
25
  Failure({a:1}).to_json # => '{"Failure": {"a":1}}'
25
26
  ```
26
27
 
28
+ Chaining successful actions
29
+
30
+ ```ruby
31
+ Success(1).and Success(2) # => Success(2)
32
+ Success(1).and_then { Success(2) } # => Success(2)
33
+
34
+ Success(1).or Success(2) # => Success(1)
35
+ Success(1).or_else { Success(2) } # => Success(1)
36
+ ```
37
+
38
+ Chaining failed actions
39
+
40
+ ```ruby
41
+ Failure(1).and Success(2) # => Failure(1)
42
+ Failure(1).and_then { Success(2) } # => Failure(1)
43
+
44
+ Failure(1).or Success(1) # => Success(1)
45
+ Failure(1).or_else { |v| Success(v)} # => Success(1)
46
+ ```
47
+
48
+ The value or block result must always be a `Success` or `Failure`
49
+
50
+
51
+
27
52
  ### Either.attempt_all
28
53
  The basic idea is to execute a chain of units of work and make sure all return either `Success` or `Failure`.
29
54
 
@@ -150,30 +175,6 @@ Success(1).match do
150
175
  end # => "catch-all"
151
176
  ```
152
177
 
153
- ## Flow control
154
-
155
- Chaininig successfull actions
156
-
157
- ```ruby
158
- Success(1).and Success(2) # => Success(2)
159
- Success(1).and_then { Success(2) } # => Success(2)
160
-
161
- Success(1).or Success(2) # => Success(1)
162
- Success(1).or_else { Success(2) } # => Success(1)
163
- ```
164
-
165
- Chaininig failed actions
166
-
167
- ```ruby
168
- Failure(1).and Success(2) # => Failure(1)
169
- Failure(1).and_then { Success(2) } # => Failure(1)
170
-
171
- Failure(1).or Success(1) # => Success(1)
172
- Failure(1).or_else { |v| Success(v)} # => Success(1)
173
- ```
174
-
175
- The value or block result must always be a `Success` or `Failure`
176
-
177
178
  ## core_ext
178
179
  You can use a core extension, to include Either in your own class or in Object, i.e. in all classes.
179
180
 
@@ -266,6 +267,7 @@ null.foo # => NoMethodError
266
267
  * [either by rsslldnphy](https://github.com/rsslldnphy/either)
267
268
  * [Functors, Applicatives, And Monads In Pictures](http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html)
268
269
  * [Naught by avdi](https://github.com/avdi/naught/)
270
+ * [Rust's Result](http://static.rust-lang.org/doc/master/std/result/enum.Result.html)
269
271
 
270
272
  ## Installation
271
273
 
@@ -24,7 +24,12 @@ class Deterministic::Either
24
24
  try_p = ->(acc) {
25
25
  begin
26
26
  value = @context.instance_exec(acc.value, &block)
27
- Deterministic::Success(value)
27
+ case value
28
+ when Success, Failure
29
+ value
30
+ else
31
+ Deterministic::Success(value)
32
+ end
28
33
  rescue => ex
29
34
  Deterministic::Failure(ex)
30
35
  end
@@ -5,7 +5,7 @@ class None
5
5
  if m == :new
6
6
  super
7
7
  else
8
- None.instance.send(m, *args)
8
+ None.instance
9
9
  end
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module Deterministic
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -72,6 +72,16 @@ describe Deterministic::Either::AttemptAll do
72
72
  ).to eq Success(2)
73
73
  end
74
74
 
75
+
76
+ it "works with boxed values" do
77
+ expect(
78
+ Either.attempt_all do
79
+ try { Failure(1) }
80
+ try { 2 }
81
+ end
82
+ ).to eq Failure(1)
83
+ end
84
+
75
85
  it "works with an OpenStruct" do
76
86
  context = OpenStruct.new
77
87
  attempt = Either.attempt_all(context) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deterministic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Zolnierek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  requirements: []
173
173
  rubyforge_project:
174
- rubygems_version: 2.2.1
174
+ rubygems_version: 2.2.2
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: see above