kleisli-validation 0.0.2 → 0.0.3
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.
- data/lib/kleisli/validation.rb +4 -58
- metadata +1 -1
data/lib/kleisli/validation.rb
CHANGED
@@ -3,19 +3,10 @@ require "kleisli"
|
|
3
3
|
require "kleisli/semigroup_instances.rb"
|
4
4
|
|
5
5
|
module Kleisli
|
6
|
-
class Validation
|
7
|
-
VERSION = "0.0.
|
6
|
+
class Validation
|
7
|
+
VERSION = "0.0.3"
|
8
8
|
|
9
|
-
|
10
|
-
self >-> f {
|
11
|
-
other >-> val {
|
12
|
-
Success(f.arity > 1 ? f.curry.call(val) : f.call(val))
|
13
|
-
}
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
class Success < Validation
|
18
|
-
alias value right
|
9
|
+
class Success < Either::Right
|
19
10
|
|
20
11
|
def *(other)
|
21
12
|
if other.class == Success
|
@@ -25,34 +16,13 @@ module Kleisli
|
|
25
16
|
end
|
26
17
|
end
|
27
18
|
|
28
|
-
def initialize(right)
|
29
|
-
@right = right
|
30
|
-
end
|
31
|
-
|
32
|
-
def >(f)
|
33
|
-
f.call(@right)
|
34
|
-
end
|
35
|
-
|
36
|
-
def fmap(&f)
|
37
|
-
Success.new(f.call(@right))
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_maybe
|
41
|
-
Maybe::Some.new(@right)
|
42
|
-
end
|
43
|
-
|
44
|
-
def or(other=nil, &other_blk)
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
19
|
def to_s
|
49
20
|
"Success(#{@right.inspect})"
|
50
21
|
end
|
51
22
|
alias inspect to_s
|
52
23
|
end
|
53
24
|
|
54
|
-
class Failure <
|
55
|
-
alias value left
|
25
|
+
class Failure < Either::Left
|
56
26
|
|
57
27
|
def *(other)
|
58
28
|
if other.class == Failure
|
@@ -67,30 +37,6 @@ module Kleisli
|
|
67
37
|
end
|
68
38
|
end
|
69
39
|
|
70
|
-
def initialize(left)
|
71
|
-
@left = left
|
72
|
-
end
|
73
|
-
|
74
|
-
def >(f)
|
75
|
-
self
|
76
|
-
end
|
77
|
-
|
78
|
-
def fmap(&f)
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
def to_maybe
|
83
|
-
Maybe::None.new
|
84
|
-
end
|
85
|
-
|
86
|
-
def or(other=self, &other_blk)
|
87
|
-
if other_blk
|
88
|
-
other_blk.call(@left)
|
89
|
-
else
|
90
|
-
other
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
40
|
def to_s
|
95
41
|
"Failure(#{@left.inspect})"
|
96
42
|
end
|