kleisli-validation 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -2
- data/lib/kleisli/validation.rb +16 -17
- metadata +1 -2
- data/lib/kleisli/validation/version.rb +0 -5
data/README.md
CHANGED
@@ -25,8 +25,7 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
Usage is practically identical to the [Either](https://github.com/txus/kleisli#either)
|
28
|
-
Monad provided by kleisli, substituting Success for Right
|
29
|
-
as well as Failure for Left (and .failure for .left).
|
28
|
+
Monad provided by kleisli, substituting Success for Right and Failure for Left.
|
30
29
|
|
31
30
|
The main difference is in the handling of errors when using the applicative
|
32
31
|
functor's apply, as seen here.
|
data/lib/kleisli/validation.rb
CHANGED
@@ -4,8 +4,7 @@ require "kleisli/semigroup_instances.rb"
|
|
4
4
|
|
5
5
|
module Kleisli
|
6
6
|
class Validation < Either
|
7
|
-
VERSION = "0.0.
|
8
|
-
attr_accessor :success, :failure
|
7
|
+
VERSION = "0.0.2"
|
9
8
|
|
10
9
|
def *(other)
|
11
10
|
self >-> f {
|
@@ -16,7 +15,7 @@ module Kleisli
|
|
16
15
|
end
|
17
16
|
|
18
17
|
class Success < Validation
|
19
|
-
alias value
|
18
|
+
alias value right
|
20
19
|
|
21
20
|
def *(other)
|
22
21
|
if other.class == Success
|
@@ -26,20 +25,20 @@ module Kleisli
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
def initialize(
|
30
|
-
@
|
28
|
+
def initialize(right)
|
29
|
+
@right = right
|
31
30
|
end
|
32
31
|
|
33
32
|
def >(f)
|
34
|
-
f.call(@
|
33
|
+
f.call(@right)
|
35
34
|
end
|
36
35
|
|
37
36
|
def fmap(&f)
|
38
|
-
Success.new(f.call(@
|
37
|
+
Success.new(f.call(@right))
|
39
38
|
end
|
40
39
|
|
41
40
|
def to_maybe
|
42
|
-
Maybe::Some.new(@
|
41
|
+
Maybe::Some.new(@right)
|
43
42
|
end
|
44
43
|
|
45
44
|
def or(other=nil, &other_blk)
|
@@ -47,29 +46,29 @@ module Kleisli
|
|
47
46
|
end
|
48
47
|
|
49
48
|
def to_s
|
50
|
-
"Success(#{@
|
49
|
+
"Success(#{@right.inspect})"
|
51
50
|
end
|
52
51
|
alias inspect to_s
|
53
52
|
end
|
54
53
|
|
55
54
|
class Failure < Validation
|
56
|
-
alias value
|
55
|
+
alias value left
|
57
56
|
|
58
57
|
def *(other)
|
59
58
|
if other.class == Failure
|
60
|
-
unless self.
|
61
|
-
self.
|
59
|
+
unless self.left.class == other.left.class &&
|
60
|
+
self.left.respond_to?(:sappend)
|
62
61
|
raise ArgumentError,
|
63
62
|
"Failures must contain members of a common Semigroup"
|
64
63
|
end
|
65
|
-
Failure(self.
|
64
|
+
Failure(self.left.sappend(other.left))
|
66
65
|
else
|
67
66
|
self
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
def initialize(
|
72
|
-
@
|
70
|
+
def initialize(left)
|
71
|
+
@left = left
|
73
72
|
end
|
74
73
|
|
75
74
|
def >(f)
|
@@ -86,14 +85,14 @@ module Kleisli
|
|
86
85
|
|
87
86
|
def or(other=self, &other_blk)
|
88
87
|
if other_blk
|
89
|
-
other_blk.call(@
|
88
|
+
other_blk.call(@left)
|
90
89
|
else
|
91
90
|
other
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
95
94
|
def to_s
|
96
|
-
"Failure(#{@
|
95
|
+
"Failure(#{@left.inspect})"
|
97
96
|
end
|
98
97
|
alias inspect to_s
|
99
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kleisli-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- kleisli-validation.gemspec
|
93
93
|
- lib/kleisli/semigroup_instances.rb
|
94
94
|
- lib/kleisli/validation.rb
|
95
|
-
- lib/kleisli/validation/version.rb
|
96
95
|
- test/kleisli/validation_test.rb
|
97
96
|
- test/test_helper.rb
|
98
97
|
homepage: ''
|