rfunk 0.2.0 → 0.3.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 +4 -4
- data/lib/rfunk/lazy.rb +1 -1
- data/lib/rfunk/{none.rb → maybe/none.rb} +8 -1
- data/lib/rfunk/maybe/option.rb +27 -0
- data/lib/rfunk/{some.rb → maybe/some.rb} +15 -3
- data/lib/rfunk/tuple.rb +27 -0
- data/lib/rfunk/version.rb +1 -1
- data/lib/rfunk.rb +11 -10
- metadata +13 -12
- data/lib/rfunk/option.rb +0 -15
- /data/lib/rfunk/{attribute.rb → attribute/attribute.rb} +0 -0
- /data/lib/rfunk/{attribute_type.rb → attribute/attribute_type.rb} +0 -0
- /data/lib/rfunk/{not_found_error.rb → attribute/not_found_error.rb} +0 -0
- /data/lib/rfunk/{either.rb → either/either.rb} +0 -0
- /data/lib/rfunk/{failure.rb → either/failure.rb} +0 -0
- /data/lib/rfunk/{success.rb → either/success.rb} +0 -0
- /data/lib/rfunk/{value.rb → either/value.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67d0f85734d6898bb2d564a59f4e3ec06e3e32b9
|
4
|
+
data.tar.gz: 5ff36ad9b6ee2c6fae4e9fc8fa10f19eb5135679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904998816f7d080cadd75e274e9a4f1321ee396d69b9c4d84e6f2ea96179018260f4a50b8fa2fb9c385b30655f80158edf1295e617a09e925380ec9f1440ff9b
|
7
|
+
data.tar.gz: a7f3a9ba4847578253c7e53357d5f1be431f05ca2073019bf8fc8f3cc23271f7820d00c6e5044de1ed9ecbdcb8a93823687b9766854b9dd32aee63efd5c64c22
|
data/lib/rfunk/lazy.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RFunk
|
2
|
-
class None
|
2
|
+
class None < Option
|
3
3
|
include Singleton
|
4
4
|
|
5
5
|
def value(default = nil)
|
@@ -13,6 +13,13 @@ module RFunk
|
|
13
13
|
def method_missing(method, *arguments, &block)
|
14
14
|
self
|
15
15
|
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def enum
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
|
16
23
|
end
|
17
24
|
|
18
25
|
def None(value = nil)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RFunk
|
2
|
+
class Option
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def each(&block)
|
6
|
+
return enum_for(:enum) if block.nil?
|
7
|
+
|
8
|
+
enum.each { |v| block.call(v) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def Option(value)
|
13
|
+
if [Some, None].map { |t| value.is_a?(t) }.any?
|
14
|
+
value
|
15
|
+
elsif nothing?(value)
|
16
|
+
None.instance
|
17
|
+
else
|
18
|
+
Some.new(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def nothing?(value)
|
25
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?) || value.is_a?(None)
|
26
|
+
end
|
27
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RFunk
|
2
|
-
class Some
|
2
|
+
class Some < Option
|
3
3
|
attr_reader :value
|
4
4
|
|
5
5
|
def initialize(value)
|
@@ -11,11 +11,23 @@ module RFunk
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def method_missing(method, *arguments, &block)
|
14
|
-
Option(value.
|
14
|
+
Option(value.send(method, *arguments, &block))
|
15
15
|
end
|
16
16
|
|
17
17
|
def ==(other)
|
18
|
-
|
18
|
+
return false unless self.class == other.class
|
19
|
+
|
20
|
+
value == other.value
|
21
|
+
end
|
22
|
+
|
23
|
+
def <=>(other)
|
24
|
+
value <=> other.value
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def enum
|
30
|
+
[value]
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
data/lib/rfunk/tuple.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module RFunk
|
2
|
+
class Tuple
|
3
|
+
def initialize(values)
|
4
|
+
@values = values
|
5
|
+
end
|
6
|
+
|
7
|
+
def value(*args)
|
8
|
+
index = args[0]
|
9
|
+
|
10
|
+
if args.length == 1
|
11
|
+
Option(values[index])
|
12
|
+
else
|
13
|
+
self.class.new(values.dup.tap { |v|
|
14
|
+
v[index] = Option(args[1])
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :values
|
22
|
+
end
|
23
|
+
|
24
|
+
def Tuple(*values)
|
25
|
+
Tuple.new(values)
|
26
|
+
end
|
27
|
+
end
|
data/lib/rfunk/version.rb
CHANGED
data/lib/rfunk.rb
CHANGED
@@ -2,16 +2,17 @@ require 'singleton'
|
|
2
2
|
require 'ice_nine'
|
3
3
|
require 'ice_nine/core_ext/object'
|
4
4
|
|
5
|
-
require 'rfunk/attribute_type'
|
6
|
-
require 'rfunk/attribute'
|
7
|
-
require 'rfunk/option'
|
8
|
-
require 'rfunk/none'
|
9
|
-
require 'rfunk/some'
|
10
|
-
require 'rfunk/not_found_error'
|
5
|
+
require 'rfunk/attribute/attribute_type'
|
6
|
+
require 'rfunk/attribute/attribute'
|
7
|
+
require 'rfunk/maybe/option'
|
8
|
+
require 'rfunk/maybe/none'
|
9
|
+
require 'rfunk/maybe/some'
|
10
|
+
require 'rfunk/attribute/not_found_error'
|
11
11
|
require 'rfunk/lazy'
|
12
|
-
require 'rfunk/value'
|
13
|
-
require 'rfunk/failure'
|
14
|
-
require 'rfunk/success'
|
15
|
-
require 'rfunk/either'
|
12
|
+
require 'rfunk/either/value'
|
13
|
+
require 'rfunk/either/failure'
|
14
|
+
require 'rfunk/either/success'
|
15
|
+
require 'rfunk/either/either'
|
16
|
+
require 'rfunk/tuple'
|
16
17
|
|
17
18
|
include RFunk
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfunk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Falkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ice_nine
|
@@ -60,17 +60,18 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- lib/rfunk.rb
|
63
|
-
- lib/rfunk/attribute.rb
|
64
|
-
- lib/rfunk/attribute_type.rb
|
65
|
-
- lib/rfunk/
|
66
|
-
- lib/rfunk/
|
63
|
+
- lib/rfunk/attribute/attribute.rb
|
64
|
+
- lib/rfunk/attribute/attribute_type.rb
|
65
|
+
- lib/rfunk/attribute/not_found_error.rb
|
66
|
+
- lib/rfunk/either/either.rb
|
67
|
+
- lib/rfunk/either/failure.rb
|
68
|
+
- lib/rfunk/either/success.rb
|
69
|
+
- lib/rfunk/either/value.rb
|
67
70
|
- lib/rfunk/lazy.rb
|
68
|
-
- lib/rfunk/none.rb
|
69
|
-
- lib/rfunk/
|
70
|
-
- lib/rfunk/
|
71
|
-
- lib/rfunk/
|
72
|
-
- lib/rfunk/success.rb
|
73
|
-
- lib/rfunk/value.rb
|
71
|
+
- lib/rfunk/maybe/none.rb
|
72
|
+
- lib/rfunk/maybe/option.rb
|
73
|
+
- lib/rfunk/maybe/some.rb
|
74
|
+
- lib/rfunk/tuple.rb
|
74
75
|
- lib/rfunk/version.rb
|
75
76
|
homepage: https://github.com/alexfalkowski/rfunk
|
76
77
|
licenses:
|
data/lib/rfunk/option.rb
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|