rfunk 1.4.1 → 1.5.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: 1ec532b32fd38be6e04ec01ae02286f819584280
4
- data.tar.gz: f212f9e4a604954c7ab0c28a1b910e346ff51098
3
+ metadata.gz: d0eb1a32853f93bfe2ebaa1548e4629afde49442
4
+ data.tar.gz: 3eb3bf01eadc2ad1821d09dc50583e7d9ada2b75
5
5
  SHA512:
6
- metadata.gz: ffd6c18290923c1389d662673b5c20ba6ca38103eed9380bf83a5544df25a68a652e090d7a3ec40d6938c6953305d9dd42ff784539fd3b6b9227b460ca81e584
7
- data.tar.gz: 64e02d009bb438c45dd3887d1c945d727e4fd067f3117bfdbeb239f4cab3d9a5cca073852a09d25eeb242ee6fb88936bc8c70de54f903e83ad03d78991e71fe4
6
+ metadata.gz: 75ebb4f28b6332111a18fede512cdf3e584874ec668b025a5789b859caee509dc2f496e9d0d247ccabac42bb15a177497c2fdff84a374eb20b26c684924e1574
7
+ data.tar.gz: 99873499286bf55002c93c4b0a314050cfc0d62f3f135ba3ce5ff951ff5ad4de6f2279555fc65d483e9b0ca00c2934c8f992ded2ab8a6a2ca50beac0ac688623
@@ -19,7 +19,7 @@ module RFunk
19
19
  variable_name: variable_name(name),
20
20
  value: value)
21
21
  else
22
- RFunk::Option(instance_variable_get(variable_name(name)))
22
+ RFunk.option(instance_variable_get(variable_name(name)))
23
23
  end
24
24
  end
25
25
  end
@@ -15,9 +15,9 @@ module RFunk
15
15
  case definition
16
16
  when Hash
17
17
  return_type = RFunk::TypeAnnotation.new(definition.values.first.to_s)
18
- RFunk::Tuple(definition.keys.first, return_type)
18
+ RFunk.tuple(definition.keys.first, return_type)
19
19
  else
20
- RFunk::Tuple(definition)
20
+ RFunk.tuple(definition)
21
21
  end
22
22
  end
23
23
  end
@@ -18,7 +18,7 @@ module RFunk
18
18
  self.variables = variables.merge(options)
19
19
  end
20
20
  else
21
- RFunk::Some(RFunk::Some(variables)[options])
21
+ RFunk.some(RFunk.some(variables)[options])
22
22
  end
23
23
  end
24
24
 
@@ -47,7 +47,7 @@ module RFunk
47
47
  execute_body_block
48
48
  else
49
49
  validate_return_type(return_value)
50
- RFunk::Option(return_value)
50
+ RFunk.option(return_value)
51
51
  end
52
52
  end
53
53
 
@@ -67,7 +67,7 @@ module RFunk
67
67
  def execute_body_block
68
68
  execute_block pre_block, RFunk::PreConditionError
69
69
 
70
- RFunk::Option(instance_eval(&body_block)).tap do |body|
70
+ RFunk.option(instance_eval(&body_block)).tap do |body|
71
71
  execute_block post_block, RFunk::PostConditionError
72
72
  validate_return_type(body)
73
73
  end
@@ -79,7 +79,7 @@ module RFunk
79
79
  end
80
80
 
81
81
  def error_checking
82
- RFunk::Lazy(-> { RFunk::ErrorChecking.new }).value
82
+ RFunk.lazy(-> { RFunk::ErrorChecking.new }).value
83
83
  end
84
84
 
85
85
  def validate_return_type(return_value)
@@ -91,7 +91,7 @@ module RFunk
91
91
  def validate_parameter_types(*args)
92
92
  values = args.zip(type_annotation.parameters)
93
93
  values.each_with_index do |v, i|
94
- tuple = RFunk::Tuple(*v)
94
+ tuple = RFunk.tuple(*v)
95
95
  error_checking.raise_expected_parameter_type(i + 1, tuple.value(0), tuple.value(1))
96
96
  end
97
97
  end
@@ -9,7 +9,7 @@ module RFunk
9
9
  when RFunk::Some, RFunk::None
10
10
  value
11
11
  else
12
- RFunk::Option(value)
12
+ RFunk.option(value)
13
13
  end
14
14
  end
15
15
 
@@ -22,31 +22,33 @@ module RFunk
22
22
  attr_reader :value
23
23
  end
24
24
 
25
- def Either(value)
26
- if lambda?(value)
27
- either_with_lambda(value)
28
- else
29
- either_with_value(value)
25
+ class << self
26
+ def either(value)
27
+ if lambda?(value)
28
+ either_with_lambda(value)
29
+ else
30
+ either_with_value(value)
31
+ end
30
32
  end
31
- end
32
33
 
33
- private
34
+ private
34
35
 
35
- def lambda?(value)
36
- value.respond_to?(:lambda?) && value.lambda?
37
- end
36
+ def lambda?(value)
37
+ value.respond_to?(:lambda?) && value.lambda?
38
+ end
38
39
 
39
- def either_with_lambda(lambda)
40
- RFunk::Success(lambda.call)
41
- rescue => e
42
- RFunk::Failure(e)
43
- end
40
+ def either_with_lambda(lambda)
41
+ RFunk.success(lambda.call)
42
+ rescue => e
43
+ RFunk.failure(e)
44
+ end
44
45
 
45
- def either_with_value(value)
46
- if value
47
- RFunk::Success(value)
48
- else
49
- RFunk::Failure(value)
46
+ def either_with_value(value)
47
+ if value
48
+ RFunk.success(value)
49
+ else
50
+ RFunk.failure(value)
51
+ end
50
52
  end
51
53
  end
52
54
  end
@@ -9,11 +9,13 @@ module RFunk
9
9
  end
10
10
 
11
11
  def or(value)
12
- RFunk::Failure(value)
12
+ RFunk.failure(value)
13
13
  end
14
14
  end
15
15
 
16
- def Failure(value)
17
- RFunk::Failure.new(value)
16
+ class << self
17
+ def failure(value)
18
+ RFunk::Failure.new(value)
19
+ end
18
20
  end
19
21
  end
@@ -13,7 +13,9 @@ module RFunk
13
13
  end
14
14
  end
15
15
 
16
- def Success(value)
17
- RFunk::Success.new(value)
16
+ class << self
17
+ def success(value)
18
+ RFunk::Success.new(value)
19
+ end
18
20
  end
19
21
  end
data/lib/rfunk/lazy.rb CHANGED
@@ -8,7 +8,7 @@ module RFunk
8
8
 
9
9
  def value
10
10
  atomic.update { @value ||= lambda.call.tap { self.created = true } }
11
- RFunk::Option(atomic.value)
11
+ RFunk.option(atomic.value)
12
12
  end
13
13
 
14
14
  def created?
@@ -21,7 +21,9 @@ module RFunk
21
21
  attr_accessor :created
22
22
  end
23
23
 
24
- def Lazy(lambda)
25
- RFunk::Lazy.new(lambda)
24
+ class << self
25
+ def lazy(lambda)
26
+ RFunk::Lazy.new(lambda)
27
+ end
26
28
  end
27
29
  end
@@ -3,11 +3,11 @@ module RFunk
3
3
  include Singleton
4
4
 
5
5
  def value(default = None())
6
- RFunk::Option(default)
6
+ RFunk.option(default)
7
7
  end
8
8
 
9
9
  def or(other)
10
- RFunk::Option(other)
10
+ RFunk.option(other)
11
11
  end
12
12
 
13
13
  def pipe(&_block)
@@ -41,7 +41,9 @@ module RFunk
41
41
  end
42
42
  end
43
43
 
44
- def None(value = nil)
45
- RFunk::Option(value)
44
+ class << self
45
+ def none(value = nil)
46
+ RFunk.option(value)
47
+ end
46
48
  end
47
49
  end
@@ -9,23 +9,25 @@ module RFunk
9
9
  end
10
10
  end
11
11
 
12
- def Option(value)
13
- if [RFunk::Some, RFunk::None].map { |t| value.is_a?(t) }.any?
14
- value
15
- elsif nothing?(value)
16
- RFunk::None.instance
17
- else
18
- RFunk::Some.new(value)
12
+ class << self
13
+ def option(value)
14
+ if [RFunk::Some, RFunk::None].map { |t| value.is_a?(t) }.any?
15
+ value
16
+ elsif nothing?(value)
17
+ RFunk::None.instance
18
+ else
19
+ RFunk::Some.new(value)
20
+ end
19
21
  end
20
- end
21
22
 
22
- private
23
+ private
23
24
 
24
- def nothing?(value)
25
- value.nil? || empty?(value) || value == RFunk::None.instance
26
- end
25
+ def nothing?(value)
26
+ value.nil? || empty?(value) || value == RFunk::None.instance
27
+ end
27
28
 
28
- def empty?(value)
29
- value.respond_to?(:empty?) && value.empty?
29
+ def empty?(value)
30
+ value.respond_to?(:empty?) && value.empty?
31
+ end
30
32
  end
31
33
  end
@@ -6,7 +6,7 @@ module RFunk
6
6
  @value = value
7
7
  end
8
8
 
9
- def value(_ = RFunk::None())
9
+ def value(_ = RFunk.none)
10
10
  @value
11
11
  end
12
12
 
@@ -16,16 +16,16 @@ module RFunk
16
16
 
17
17
  def pipe(&block)
18
18
  return self if block.nil?
19
- RFunk::Option(yield value)
19
+ RFunk.option(yield value)
20
20
  end
21
21
 
22
22
  def method_missing(method, *arguments, &block)
23
- RFunk::Option(value.send(method, *arguments, &block))
23
+ RFunk.option(value.send(method, *arguments, &block))
24
24
  end
25
25
 
26
26
  def ==(other)
27
27
  return false unless self.class == other.class
28
- value == Option(other).value
28
+ value == RFunk.option(other).value
29
29
  end
30
30
 
31
31
  def <=>(other)
@@ -53,7 +53,9 @@ module RFunk
53
53
  end
54
54
  end
55
55
 
56
- def Some(value)
57
- RFunk::Option(value)
56
+ class << self
57
+ def some(value)
58
+ RFunk.option(value)
59
+ end
58
60
  end
59
61
  end
data/lib/rfunk/tuple.rb CHANGED
@@ -9,9 +9,9 @@ module RFunk
9
9
  index = args[0]
10
10
 
11
11
  if args.length == 1
12
- RFunk::Option(values[index])
12
+ RFunk.option(values[index])
13
13
  else
14
- self.class.new(values.dup.tap { |v| v[index] = RFunk::Option(args[1]) })
14
+ self.class.new(values.dup.tap { |v| v[index] = RFunk.option(args[1]) })
15
15
  end
16
16
  end
17
17
 
@@ -20,7 +20,9 @@ module RFunk
20
20
  attr_reader :values
21
21
  end
22
22
 
23
- def Tuple(*values)
24
- RFunk::Tuple.new(values)
23
+ class << self
24
+ def tuple(*values)
25
+ RFunk::Tuple.new(values)
26
+ end
25
27
  end
26
28
  end
data/lib/rfunk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RFunk
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
  end
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: 1.4.1
4
+ version: 1.5.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: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_nine