simple_monads 0.1.4 → 1.0.2
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: 867cc1b4a8447431e58c0da67734ec03ed3f2a771adec946eb0e846e7f3334f9
|
4
|
+
data.tar.gz: 13cef8004c2d150275b53521e81b8927fe08872b815e79092f0077b645aa4ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d3cba8776910cc8bf8affffb2bd7640d5785dc0b6240ac42d73554830dee1f2119ecd3184a0b191fa377e4f2cfac72da59ee3b3fb18e30f9736fc987378bc82
|
7
|
+
data.tar.gz: 3a505b14fc6db260c8b0fd3b95306f9bbfdb67685d5e8b541fddd1b0a7202128f51ba9500e16c0c4b739b6c152bf8a686490b19b74343683424ba6faf109ddbf
|
@@ -1,25 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SimpleMonads
|
4
|
-
#
|
5
|
-
class
|
4
|
+
# Base Result monads
|
5
|
+
class BaseResult
|
6
6
|
attr_reader :object
|
7
|
-
alias failure object
|
8
7
|
|
9
8
|
def initialize(object = nil)
|
10
9
|
@object = object
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def success?
|
18
|
-
false
|
12
|
+
def success_or(value)
|
13
|
+
failure? ? value : success
|
19
14
|
end
|
20
15
|
|
21
16
|
def inspect
|
22
|
-
"
|
17
|
+
"#{self.class.to_s[14..-7]}(#{object})"
|
23
18
|
end
|
24
19
|
end
|
25
20
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_result'
|
4
|
+
|
5
|
+
module SimpleMonads
|
6
|
+
# failure object
|
7
|
+
class FailureResult < BaseResult
|
8
|
+
alias failure object
|
9
|
+
|
10
|
+
def failure?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
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 = nil)
|
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
8
|
def Success(object = nil) # rubocop:disable Naming/MethodName
|
9
|
-
|
9
|
+
SuccessResult.new(object)
|
10
10
|
end
|
11
11
|
|
12
12
|
def Failure(object = nil) # rubocop:disable Naming/MethodName
|
13
|
-
|
13
|
+
FailureResult.new(object)
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_monads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Leonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple monads without DRY dependencies
|
14
14
|
email: leonov835@yandex.ru
|
@@ -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:
|
@@ -42,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
43
|
- !ruby/object:Gem::Version
|
43
44
|
version: '0'
|
44
45
|
requirements: []
|
45
|
-
rubygems_version: 3.5.
|
46
|
+
rubygems_version: 3.5.22
|
46
47
|
signing_key:
|
47
48
|
specification_version: 4
|
48
49
|
summary: Simple monads
|