totally_lazy 0.0.20 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/compiler.xml +22 -0
- data/.idea/encodings.xml +6 -0
- data/.idea/misc.xml +19 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.travis.yml +2 -5
- data/Gemfile +6 -8
- data/Guardfile +2 -17
- data/LICENSE +202 -0
- data/Rakefile +18 -33
- data/VERSION +1 -1
- data/contributors.txt +1 -0
- data/lib/comparators.rb +9 -0
- data/lib/enumerators.rb +74 -0
- data/lib/functions.rb +66 -0
- data/lib/numbers.rb +38 -0
- data/lib/option.rb +38 -268
- data/lib/pair.rb +13 -51
- data/lib/predicates.rb +5 -0
- data/lib/sequence.rb +171 -526
- data/lib/strings.rb +13 -0
- data/lib/totally_lazy.rb +14 -165
- data/readme.md +2 -0
- data/spec/option_spec.rb +6 -182
- data/spec/sequence_spec.rb +202 -132
- data/spec/spec_helper.rb +0 -13
- data/totally_lazy.iml +74 -0
- metadata +58 -71
- data/.document +0 -5
- data/.rspec +0 -1
- data/LICENSE.txt +0 -20
- data/README.md +0 -173
- data/lib/any.rb +0 -13
- data/lib/functor.rb +0 -92
- data/lib/generators.rb +0 -161
- data/lib/parallel/parallel.rb +0 -442
- data/lib/parallel/processor_count.rb +0 -85
- data/lib/predicates/compare.rb +0 -25
- data/lib/predicates/conversions.rb +0 -22
- data/lib/predicates/numbers.rb +0 -21
- data/lib/predicates/predicates.rb +0 -141
- data/lib/predicates/where.rb +0 -34
- data/lib/predicates/where_processor.rb +0 -13
- data/lib/type_check.rb +0 -19
- data/lib/utils.rb +0 -9
- data/spec/functor_spec.rb +0 -35
- data/spec/generators_spec.rb +0 -37
- data/spec/pair_spec.rb +0 -44
- data/spec/predicate_spec.rb +0 -77
- data/spec/serialization_spec.rb +0 -56
- data/spec/type_check_spec.rb +0 -20
- data/spec/util_spec.rb +0 -10
- data/totally_lazy.gemspec +0 -101
@@ -1,141 +0,0 @@
|
|
1
|
-
module Predicates
|
2
|
-
|
3
|
-
class Predicate
|
4
|
-
|
5
|
-
def inverted(v, meth, pred)
|
6
|
-
if meth == :self
|
7
|
-
Type.responds(v, pred)
|
8
|
-
v unless v.send(pred)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def regular(v, meth, pred)
|
13
|
-
if meth == :self
|
14
|
-
Type.responds(v, pred)
|
15
|
-
v if v.send(pred)
|
16
|
-
else
|
17
|
-
r = v.send(meth)
|
18
|
-
Type.responds(r, pred)
|
19
|
-
v if r.send(pred)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def inverted_value(v, value, meth, pred)
|
24
|
-
if meth == :self
|
25
|
-
Type.responds(v, pred)
|
26
|
-
v unless v.send(pred, value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def regular_value(v, value, meth, pred)
|
31
|
-
if meth == :self
|
32
|
-
Type.responds(v, pred)
|
33
|
-
v if v.send(pred, value)
|
34
|
-
else
|
35
|
-
r = v.send(meth)
|
36
|
-
Type.responds(r, pred)
|
37
|
-
v if r.send(pred, value)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def regular_regex(v, regex, meth)
|
42
|
-
if meth == :self
|
43
|
-
v if v.to_s.match(regex)
|
44
|
-
else
|
45
|
-
r = v.send(meth)
|
46
|
-
v if r.to_s.match(regex)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def inverted_regex(v, regex, meth)
|
51
|
-
if meth == :self
|
52
|
-
v unless v.to_s.match(regex)
|
53
|
-
else
|
54
|
-
r = v.send(meth)
|
55
|
-
v unless r.to_s.match(regex)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def value_predicate(name, pred, value)
|
62
|
-
ValuePredicate.new(name, pred, value)
|
63
|
-
end
|
64
|
-
|
65
|
-
def regex_predicate(name, value)
|
66
|
-
RegexPredicate.new(name, value)
|
67
|
-
end
|
68
|
-
|
69
|
-
def self_predicate(name,pred)
|
70
|
-
SelfPredicate.new(name,pred)
|
71
|
-
end
|
72
|
-
|
73
|
-
def simple_transform(name,exec)
|
74
|
-
SimpleTransform.new(name,exec)
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
class ValuePredicate < Predicates::Predicate
|
79
|
-
|
80
|
-
attr_reader :name, :pred, :value
|
81
|
-
|
82
|
-
def initialize(name, pred, value)
|
83
|
-
@name = name
|
84
|
-
@pred = pred
|
85
|
-
@value = value
|
86
|
-
end
|
87
|
-
|
88
|
-
def exec
|
89
|
-
-> (v, meth=:self, invert=false) do
|
90
|
-
invert ? inverted_value(v, @value, meth, @pred) : regular_value(v, @value, meth, @pred)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
class SelfPredicate < Predicates::Predicate
|
97
|
-
|
98
|
-
attr_reader :name, :pred
|
99
|
-
|
100
|
-
def initialize(name, pred)
|
101
|
-
@name = name
|
102
|
-
@pred = pred
|
103
|
-
end
|
104
|
-
|
105
|
-
def exec
|
106
|
-
-> (v, meth=:self, invert=false) do
|
107
|
-
invert ? inverted(v, meth, @pred) : regular(v, meth, @pred)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
class SimpleTransform < Predicates::Predicate
|
114
|
-
attr_reader :name, :exec
|
115
|
-
|
116
|
-
def initialize(name, exec)
|
117
|
-
@name = name
|
118
|
-
@exec = exec
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
class RegexPredicate < Predicates::Predicate
|
124
|
-
|
125
|
-
attr_reader :name, :value
|
126
|
-
|
127
|
-
def initialize(name, value)
|
128
|
-
@name = name
|
129
|
-
@value = value
|
130
|
-
end
|
131
|
-
|
132
|
-
def exec
|
133
|
-
-> (v, meth=:self, invert=false) do
|
134
|
-
invert ? inverted_regex(v, @value, meth) : regular_regex(v, @value, meth)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
end
|
data/lib/predicates/where.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Predicates
|
2
|
-
|
3
|
-
module Where
|
4
|
-
class WherePredicate
|
5
|
-
|
6
|
-
attr_reader :predicates
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@predicates = empty
|
10
|
-
end
|
11
|
-
|
12
|
-
def where(predicates)
|
13
|
-
@predicates = predicates.is_a?(Pair::Pair) ? @predicates.append(predicates) : @predicates.join(Pair.from_map(predicates))
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def and(predicates)
|
18
|
-
@predicates = predicates.is_a?(Pair::Pair) ? @predicates.append(predicates) : @predicates.join(Pair.from_map(predicates))
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def where(predicate_map)
|
25
|
-
WherePredicate.new.where(predicate_map)
|
26
|
-
end
|
27
|
-
|
28
|
-
def is(single_predicate)
|
29
|
-
pair(:self, single_predicate)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class WhereProcessor
|
2
|
-
def initialize(value)
|
3
|
-
@value = value
|
4
|
-
end
|
5
|
-
|
6
|
-
def apply(predicates, invert=false)
|
7
|
-
if invert
|
8
|
-
@value if predicates.map { |x| x.value.exec.call(@value, x.key) }.contains?(nil)
|
9
|
-
else
|
10
|
-
@value unless predicates.map { |x| x.value.exec.call(@value, x.key) }.contains?(nil)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/type_check.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Type
|
2
|
-
|
3
|
-
def self.check(actual, expected)
|
4
|
-
raise(UnsupportedTypeException.new, "Target must be of type: #{expected} but was: #{actual.class}") unless actual.kind_of?(expected)
|
5
|
-
actual
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.responds(value, meth)
|
9
|
-
raise(UnsupportedTypeException.new, "Target must respond to: #{meth} - but did not with: #{value.class} of: #{value.inspect}") unless value.respond_to?(meth)
|
10
|
-
value
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.responds_all(values, meth)
|
14
|
-
values.each do |value|
|
15
|
-
raise(UnsupportedTypeException.new, "Target must respond to: #{meth} - but did not with: #{value.class} of: #{value.inspect}") unless value.respond_to?(meth)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/lib/utils.rb
DELETED
data/spec/functor_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Functor' do
|
4
|
-
|
5
|
-
it 'should create a new functor' do
|
6
|
-
fc = Functor.new do |op, *a, &b|
|
7
|
-
[op, a, b]
|
8
|
-
end
|
9
|
-
expect(fc+1).to eq([:+, [1], nil])
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should support class method' do
|
13
|
-
fc = Functor.new do |op, *a, &b|
|
14
|
-
[op, a, b]
|
15
|
-
end
|
16
|
-
expect( fc.__class__).to eq(Functor)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should support to proc' do
|
20
|
-
f = Functor.new do |op, *a|
|
21
|
-
[op, *a]
|
22
|
-
end
|
23
|
-
p = f.to_proc
|
24
|
-
expect(p.class).to eq(Proc)
|
25
|
-
expect(p.call(:+,1,2,3)).to eq([:+,1,2,3])
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should cache a new functor' do
|
29
|
-
Functor.cache(:cached) do |op, *a, &b|
|
30
|
-
[op, a, b]
|
31
|
-
end
|
32
|
-
expect(Functor.cache(:cached) + 1).to eq([:+, [1], nil])
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/spec/generators_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Generators' do
|
4
|
-
|
5
|
-
it 'should support repeat' do
|
6
|
-
expect(Seq.repeat('car').take(2)).to eq(sequence('car', 'car'))
|
7
|
-
expect(Iter.repeat('car').take(2).entries).to eq(%w(car car))
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should support range' do
|
11
|
-
expect(Seq.range(1, 4)).to eq(sequence(1, 2, 3, 4))
|
12
|
-
expect(Iter.range(1, 4).entries).to eq([1, 2, 3, 4])
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should support iterate' do
|
16
|
-
expect(Seq.iterate(:+, 1).take(4)).to eq(sequence(1, 2, 3, 4))
|
17
|
-
expect(Iter.iterate(:+, 1).take(4).entries).to eq([1, 2, 3, 4])
|
18
|
-
expect(Seq.iterate(:+, 1, 5).take(4)).to eq(sequence(5, 6, 7, 8))
|
19
|
-
expect(Iter.iterate(:+, 1, 5).take(4).entries).to eq([5, 6, 7, 8])
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should support primes' do
|
23
|
-
expect(Seq.primes.take(3)).to eq(sequence(2, 3, 5))
|
24
|
-
expect(Iter.primes.take(3).entries).to eq([2, 3, 5])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should support fibonacci' do
|
28
|
-
expect(Seq.fibonacci.take(3)).to eq(sequence(1, 1, 2))
|
29
|
-
expect(Iter.fibonacci.take(3).entries).to eq([1, 1, 2])
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should support powers_of' do
|
33
|
-
expect(Seq.range(1, 4)).to eq(sequence(1, 2, 3, 4))
|
34
|
-
expect(Iter.range(1, 4).entries).to eq([1, 2, 3, 4])
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/spec/pair_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Pair' do
|
4
|
-
|
5
|
-
it 'should return the first item: first/key' do
|
6
|
-
expect(pair(1, 2).first).to eq(1)
|
7
|
-
expect(pair(1, 2).key).to eq(1)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should return the second item: second/value' do
|
11
|
-
expect(pair(1, 2).second).to eq(2)
|
12
|
-
expect(pair(1, 2).value).to eq(2)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should return sequence of values' do
|
16
|
-
expect(pair(1, 2).values).to eq(sequence(1, 2))
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should convert to string' do
|
20
|
-
expect(pair('apples', 2).to_s).to eq({'apples' => '2'})
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should convert to a sequence of pairs from a map' do
|
24
|
-
expect(Pair.from_map({apples: '10'}).to_a).to eq(sequence(pair(:apples, '10')).to_a)
|
25
|
-
expect(Pair.from_map({:one => 1, :two => 2}).to_a).to eq(sequence(pair(:one,1),pair(:two,2)).to_a)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should convert a pair to a map' do
|
29
|
-
expect(pair(1, 2).to_map).to eq({1 => 2})
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should convert to int' do
|
33
|
-
expect(pair('1', '2').to_i).to eq({1 => 2})
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should convert to float' do
|
37
|
-
expect(pair('1', '2').to_f).to eq({1.0 => 2.0})
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should support each' do
|
41
|
-
expect(pair(1,2).each{|x| x }).to eq([1,2])
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
data/spec/predicate_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Predicates' do
|
4
|
-
|
5
|
-
it 'should return only even numbers' do
|
6
|
-
expect(sequence(1,2,3,4,5,6).filter(even)).to eq(sequence(2,4,6))
|
7
|
-
expect(sequence(1,2,3,4,5,6).unfilter(odd)).to eq(sequence(2,4,6))
|
8
|
-
expect { sequence(pair(1,2),pair(3,4)).filter(even).entries }.to raise_error(UnsupportedTypeException)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should return only odd numbers' do
|
12
|
-
expect(sequence(1,2,3,4,5,6).filter(odd)).to eq(sequence(1,3,5))
|
13
|
-
expect(sequence(1,2,3,4,5,6).unfilter(even)).to eq(sequence(1,3,5))
|
14
|
-
expect { sequence(pair(1,2),pair(3,4)).filter(odd).entries }.to raise_error(UnsupportedTypeException)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should support map' do
|
18
|
-
expect(sequence(1,2).map(as_string)).to eq(sequence("1","2"))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should support flat_map' do
|
22
|
-
expect(sequence(sequence(1, 2), sequence(3, 4)).flat_map(as_string).to_a).to eq(sequence("1", "2", "3", "4").to_a)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should return content as string' do
|
26
|
-
expect(sequence(1,2).map(as_string)).to eq(sequence("1","2"))
|
27
|
-
expect(sequence(pair(1,2),pair(3,4)).map(as_string).entries).to eq([{'1'=>'2'},{'3'=>'4'}])
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should return content as int' do
|
31
|
-
expect(sequence('1','2').map(as_int)).to eq(sequence(1,2))
|
32
|
-
expect(sequence(pair('1','2'),pair('3','4')).map(as_int).entries).to eq([{1=>2}, {3=>4}])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should return content as float' do
|
36
|
-
expect(sequence(1,2).map(as_float)).to eq(sequence(1.0,2.0))
|
37
|
-
expect(sequence(pair(1,2),pair(3,4)).map(as_float).entries).to eq([{1.0=>2.0}, {3.0=>4.0}])
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should return content as array' do
|
41
|
-
expect(sequence(1,2).map(as_array)).to eq(sequence([1],[2]))
|
42
|
-
expect(sequence(pair(1,2),pair(3,4)).map(as_array).head.class).to eq(Array)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should work with basic where predicates' do
|
46
|
-
expect(sequence(1,2,3).filter(where(is greater_than 1))).to eq(sequence(2,3))
|
47
|
-
expect(sequence(1,2,3).filter(where(is greater_than 1).and(is less_than 3))).to eq(sequence(2))
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should work with method where predicates' do
|
51
|
-
expect(sequence(pair(1,2),pair(3,4),pair(5,7)).filter(where(key:greater_than(1)).and(value:odd)).to_a).to eq(sequence(pair(5,7)).to_a)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should work with inverted value predicates' do
|
55
|
-
expect(sequence(1,2,3,4,5).reject(where(is Compare.equal_to 3))).to eq(sequence(1,2,4,5))
|
56
|
-
expect(sequence(pair(1,2),pair(3,4),pair(5,7)).reject(where value:odd).to_a).to eq(sequence(pair(1,2),pair(3,4)).to_a)
|
57
|
-
expect(sequence(pair(1,2),pair(3,4),pair(5,7)).reject(where value:equals(2)).to_a).to eq(sequence(pair(3,4),pair(5,7)).to_a)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should work with symbols as values when applying predicates' do
|
61
|
-
expect(sequence(pair(:people,sequence(1,2)), pair(:swans,10)).filter(where(key:equals(:swans))).to_a).to eq(sequence(pair(:swans,10)).to_a)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should work with inverted predicates' do
|
65
|
-
expect(sequence(1,2,3,4,5).reject(where(is odd))).to eq(sequence(2,4))
|
66
|
-
expect(sequence(1,2,3,4,5).reject(odd)).to eq(sequence(2,4))
|
67
|
-
expect(sequence(1,2,3,4,5).reject(greater_than 2)).to eq(sequence(1,2))
|
68
|
-
expect(sequence(1,2,3,4,5).filter(greater_than 2)).to eq(sequence(3,4,5))
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should work with regex predicates' do
|
72
|
-
expect(sequence(pair('apples','pears'),pair('banana','orange'),pair('apples','melon')).filter(where key:matches(/app/)).to_a).to eq(sequence(pair('apples','pears'),pair('apples','melon')).to_a)
|
73
|
-
expect(sequence(pair('apples','pears'),pair('banana','orange'),pair('apples','melon')).reject(where key:matches(/app/)).to_a).to eq(sequence(pair('banana','orange')).to_a)
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
end
|
data/spec/serialization_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Sequence Serialization/Deserialization' do
|
4
|
-
|
5
|
-
it 'should serialize a sequence' do
|
6
|
-
serialized = sequence(pair(7, 8), sequence(1, 2), sequence(3, sequence(5, 6)), sequence(pair(:apple, 99), option(1), none), [10, 11], {:apple => 8, :pear => 9}).serialize
|
7
|
-
expect(serialized).to eq([{:type => :pair, :values => {7 => 8}}, {:type => :sequence, :values => [1, 2]}, {:type => :sequence, :values => [3, {:type => :sequence, :values => [5, 6]}]}, {:type => :sequence, :values => [{:type => :pair, :values => {:apple => 99}}, {:type => :some, :values => 1}, {:type => :none, :values => nil}]}, {:type => Array, :values => [10, 11]}, {:type => Hash, :values => [{:type => Array, :values => [:apple, 8]}, {:type => Array, :values => [:pear, 9]}]}])
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should serialize a pair containing sequences' do
|
11
|
-
serialized = sequence(pair(:people,sequence(1,2))).serialize
|
12
|
-
expect(serialized).to eq([{:type => :pair, :values => [:people, {:type => :sequence, :values => [1,2]}]}])
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should deserialize a pair containing sequences' do
|
16
|
-
serialized = sequence(pair(:people,sequence(1,2))).serialize
|
17
|
-
expect(deserialize(serialized)[0].key).to eq(:people)
|
18
|
-
expect(deserialize(serialized)[0].value).to eq(sequence(1,2))
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should deserialize a serialized sequence containing pair' do
|
22
|
-
expect(seq[0].to_map).to eq(pair(7, 8).to_map)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should deserialize a serialized sequence containing sequence' do
|
26
|
-
expect(seq[1]).to eq(sequence(1, 2))
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should deserialize a serialized sequence containing nested sequence' do
|
30
|
-
expect(seq[2]).to eq(sequence(3, sequence(5, 6)))
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should deserialize a serialized sequence containing some' do
|
34
|
-
expect(seq[3][1]).to eq(option(1))
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should deserialize a serialized sequence containing none' do
|
38
|
-
expect(seq[3][2]).to eq(none)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should deserialize a serialized sequence containing an array' do
|
42
|
-
expect(seq[4]).to eq([10,11])
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should deserialize a serialized sequence containing a hash' do
|
46
|
-
expect(seq[5]).to eq({:apple => 8, :pear => 9})
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def seq
|
52
|
-
serialized = sequence(pair(7, 8), sequence(1, 2), sequence(3, sequence(5, 6)), sequence(pair(:apple, 99), option(1), none), [10, 11], {:apple => 8, :pear => 9}).serialize
|
53
|
-
deserialize(serialized)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/spec/type_check_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Type Check' do
|
4
|
-
|
5
|
-
it 'should raise UnsupportedTypeException exception if value is not of specified type' do
|
6
|
-
expect(Type.check(1, Fixnum)).to eq(1)
|
7
|
-
expect { Type.check('1', Fixnum) }.to raise_error(UnsupportedTypeException)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should raise UnsupportedTypeException exception if value does not respond to specified method' do
|
11
|
-
expect(Type.responds(1, :even?)).to eq(1)
|
12
|
-
expect { Type.responds('1', :even?) }.to raise_error(UnsupportedTypeException)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should raise UnsupportedTypeException exception if values do not respond to specified method' do
|
16
|
-
expect(Type.responds_all(sequence(1,2,3), :to_s)).to eq([1,2,3])
|
17
|
-
expect { Type.responds_all(sequence(1,2,3), :is_cool) }.to raise_error(UnsupportedTypeException)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/util_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe 'Maps' do
|
4
|
-
|
5
|
-
it 'should return a sequence of maps as a merged map' do
|
6
|
-
expect(Maps.merge(sequence(:a,2,:b,4).to_maps)).to eq({a:2,b:4})
|
7
|
-
expect(Maps.merge(sequence(1,2,3,4).to_maps(false))).to eq({1=>2,3=>4})
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
data/totally_lazy.gemspec
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: totally_lazy 0.0.20 ruby lib
|
6
|
-
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = "totally_lazy"
|
9
|
-
s.version = "0.0.20"
|
10
|
-
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Kingsley Hendrickse"]
|
14
|
-
s.date = "2015-11-09"
|
15
|
-
s.description = "Port of java functional library totally lazy to ruby"
|
16
|
-
s.email = "kingsleyhendrickse@me.com"
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE.txt",
|
19
|
-
"README.md"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
".rspec",
|
24
|
-
".travis.yml",
|
25
|
-
"Gemfile",
|
26
|
-
"Guardfile",
|
27
|
-
"LICENSE.txt",
|
28
|
-
"README.md",
|
29
|
-
"Rakefile",
|
30
|
-
"VERSION",
|
31
|
-
"lib/any.rb",
|
32
|
-
"lib/functor.rb",
|
33
|
-
"lib/generators.rb",
|
34
|
-
"lib/option.rb",
|
35
|
-
"lib/pair.rb",
|
36
|
-
"lib/parallel/parallel.rb",
|
37
|
-
"lib/parallel/processor_count.rb",
|
38
|
-
"lib/predicates/compare.rb",
|
39
|
-
"lib/predicates/conversions.rb",
|
40
|
-
"lib/predicates/numbers.rb",
|
41
|
-
"lib/predicates/predicates.rb",
|
42
|
-
"lib/predicates/where.rb",
|
43
|
-
"lib/predicates/where_processor.rb",
|
44
|
-
"lib/sequence.rb",
|
45
|
-
"lib/totally_lazy.rb",
|
46
|
-
"lib/type_check.rb",
|
47
|
-
"lib/utils.rb",
|
48
|
-
"spec/functor_spec.rb",
|
49
|
-
"spec/generators_spec.rb",
|
50
|
-
"spec/option_spec.rb",
|
51
|
-
"spec/pair_spec.rb",
|
52
|
-
"spec/predicate_spec.rb",
|
53
|
-
"spec/sequence_spec.rb",
|
54
|
-
"spec/serialization_spec.rb",
|
55
|
-
"spec/spec_helper.rb",
|
56
|
-
"spec/type_check_spec.rb",
|
57
|
-
"spec/util_spec.rb",
|
58
|
-
"totally_lazy.gemspec"
|
59
|
-
]
|
60
|
-
s.homepage = "http://github.com/kingsleyh/totally_lazy"
|
61
|
-
s.licenses = ["MIT"]
|
62
|
-
s.rubygems_version = "2.4.5.1"
|
63
|
-
s.summary = "Port of java functional library totally lazy to ruby"
|
64
|
-
|
65
|
-
if s.respond_to? :specification_version then
|
66
|
-
s.specification_version = 4
|
67
|
-
|
68
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
|
-
s.add_development_dependency(%q<rspec>, ["~> 3.0.0"])
|
70
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
71
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
72
|
-
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
73
|
-
s.add_development_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
74
|
-
s.add_development_dependency(%q<rake>, ["~> 10.3.2"])
|
75
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
76
|
-
s.add_development_dependency(%q<coveralls>, [">= 0"])
|
77
|
-
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
80
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
81
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
82
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
83
|
-
s.add_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
84
|
-
s.add_dependency(%q<rake>, ["~> 10.3.2"])
|
85
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
86
|
-
s.add_dependency(%q<coveralls>, [">= 0"])
|
87
|
-
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
88
|
-
end
|
89
|
-
else
|
90
|
-
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
91
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
92
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
93
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
94
|
-
s.add_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
95
|
-
s.add_dependency(%q<rake>, ["~> 10.3.2"])
|
96
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
97
|
-
s.add_dependency(%q<coveralls>, [">= 0"])
|
98
|
-
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|