rfunk 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 19d4d78e7405dd0df4292227a632888722874ea1
4
- data.tar.gz: a7c3e340bbc434670d8a524d8c30ff8a7923bab9
3
+ metadata.gz: 67d0f85734d6898bb2d564a59f4e3ec06e3e32b9
4
+ data.tar.gz: 5ff36ad9b6ee2c6fae4e9fc8fa10f19eb5135679
5
5
  SHA512:
6
- metadata.gz: d74968aa0449b85a88e54e5bfc876cefe809937eb38a21c4e5b7038ce669de34aef258509f373bb1f4be2014d5e5fed1ffd71c464c89a42030b096340d58b6c3
7
- data.tar.gz: 0ce78139b5124ee24939f52f2e58eea0ab963f642349e21827070d7b5d46d447b3f5dbb46fb5388eef05068e9df9e7cc011da7ef9259bf3913d1add235e942fc
6
+ metadata.gz: 904998816f7d080cadd75e274e9a4f1321ee396d69b9c4d84e6f2ea96179018260f4a50b8fa2fb9c385b30655f80158edf1295e617a09e925380ec9f1440ff9b
7
+ data.tar.gz: a7f3a9ba4847578253c7e53357d5f1be431f05ca2073019bf8fc8f3cc23271f7820d00c6e5044de1ed9ecbdcb8a93823687b9766854b9dd32aee63efd5c64c22
data/lib/rfunk/lazy.rb CHANGED
@@ -6,7 +6,7 @@ module RFunk
6
6
  end
7
7
 
8
8
  def value
9
- Option(@value ||= lambda.call.tap { self.created = true })
9
+ Option(@value ||= lambda.call.tap { self.created = true })
10
10
  end
11
11
 
12
12
  def created?
@@ -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.__send__(method, *arguments, &block))
14
+ Option(value.send(method, *arguments, &block))
15
15
  end
16
16
 
17
17
  def ==(other)
18
- other.value == value
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RFunk
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.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-08 00:00:00.000000000 Z
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/either.rb
66
- - lib/rfunk/failure.rb
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/not_found_error.rb
70
- - lib/rfunk/option.rb
71
- - lib/rfunk/some.rb
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
@@ -1,15 +0,0 @@
1
- module RFunk
2
- def Option(value)
3
- if nothing?(value)
4
- None.instance
5
- else
6
- Some.new(value)
7
- end
8
- end
9
-
10
- private
11
-
12
- def nothing?(value)
13
- value.nil? || (value.respond_to?(:empty?) && value.empty?) || value.is_a?(None)
14
- end
15
- end
File without changes
File without changes
File without changes
File without changes
File without changes