simple_monads 0.1.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94ecfa1549564c8e6f726c18e4d09b46c24c4d17b12d9e1b02ba53b604e0ddc0
|
4
|
+
data.tar.gz: dd767fac73d0c49e5603d2a47b1fd9a04ad47f42d434f26a9cf5839e68fc8f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9778bda3dc98d15313ff29d30ecc97463064d3ae8c3d144d59a6f75484fa1adbf931b3149fc1e05fdf756fe6f47df6cd62169331e9b32b0fdd46dc6fc347bc8c
|
7
|
+
data.tar.gz: 6887ac7f26aa1af71b010707078649f6438775bc2303dba22f6972b4d2565035df75b9b45428b3da84f2f00038bd41d9b8552e57f3922dabfa70c7a9d0fa49db
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleMonads
|
4
|
+
# Base Result monads
|
5
|
+
class BaseResult
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize(object = nil)
|
9
|
+
@object = object
|
10
|
+
end
|
11
|
+
|
12
|
+
def success_or(value)
|
13
|
+
failure? ? value : success
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
"#{self.class.to_s[14..-7]}(#{object})"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,15 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'base_result'
|
4
|
+
|
3
5
|
module SimpleMonads
|
4
6
|
# failure object
|
5
|
-
class
|
6
|
-
attr_reader :object
|
7
|
+
class FailureResult < BaseResult
|
7
8
|
alias failure object
|
8
9
|
|
9
|
-
def initialize(object)
|
10
|
-
@object = object
|
11
|
-
end
|
12
|
-
|
13
10
|
def failure?
|
14
11
|
true
|
15
12
|
end
|
@@ -17,9 +14,5 @@ module SimpleMonads
|
|
17
14
|
def success?
|
18
15
|
false
|
19
16
|
end
|
20
|
-
|
21
|
-
def inspect
|
22
|
-
"Failure(#{object})"
|
23
|
-
end
|
24
17
|
end
|
25
18
|
end
|
@@ -1,15 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'base_result'
|
4
|
+
|
3
5
|
module SimpleMonads
|
4
6
|
# success object
|
5
|
-
class
|
6
|
-
attr_reader :object
|
7
|
+
class SuccessResult < BaseResult
|
7
8
|
alias success object
|
8
9
|
|
9
|
-
def initialize(object)
|
10
|
-
@object = object
|
11
|
-
end
|
12
|
-
|
13
10
|
def failure?
|
14
11
|
false
|
15
12
|
end
|
@@ -17,9 +14,5 @@ module SimpleMonads
|
|
17
14
|
def success?
|
18
15
|
true
|
19
16
|
end
|
20
|
-
|
21
|
-
def inspect
|
22
|
-
"Success(#{object})"
|
23
|
-
end
|
24
17
|
end
|
25
18
|
end
|
data/lib/simple_monads.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'simple_monads/
|
4
|
-
require_relative 'simple_monads/
|
3
|
+
require_relative 'simple_monads/failure_result'
|
4
|
+
require_relative 'simple_monads/success_result'
|
5
5
|
|
6
6
|
# Main module
|
7
7
|
module SimpleMonads
|
8
|
-
def Success(object) # rubocop:disable Naming/MethodName
|
9
|
-
|
8
|
+
def Success(object = nil) # rubocop:disable Naming/MethodName
|
9
|
+
SuccessResult.new(object)
|
10
10
|
end
|
11
11
|
|
12
|
-
def Failure(object) # rubocop:disable Naming/MethodName
|
13
|
-
|
12
|
+
def Failure(object = nil) # rubocop:disable Naming/MethodName
|
13
|
+
FailureResult.new(object)
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_monads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Leonov
|
@@ -17,8 +17,9 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/simple_monads.rb
|
20
|
-
- lib/simple_monads/
|
21
|
-
- lib/simple_monads/
|
20
|
+
- lib/simple_monads/base_result.rb
|
21
|
+
- lib/simple_monads/failure_result.rb
|
22
|
+
- lib/simple_monads/success_result.rb
|
22
23
|
- lib/simple_monads/version.rb
|
23
24
|
homepage: https://github.com/leonovk/simple_monads
|
24
25
|
licenses:
|