totally_lazy 0.0.11 → 0.0.12

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: 779623e20c4ee519261bb0b42e2a505d08f9acca
4
- data.tar.gz: 3cb2bb9c54498c152c657db104c8a75fd983caef
3
+ metadata.gz: 0f349b796deda1ef4fcc94670c205949b50ef43e
4
+ data.tar.gz: 4dc70d58fdb8a03b646a2b719b3a0576abd55107
5
5
  SHA512:
6
- metadata.gz: a6dfea8db53b757f7d59edae87ae8703e0556b45aa3975f2aa868389bcec32e9b38404de562f086d04618b35eda89b17491cf444605ac9c7424bc92775107158
7
- data.tar.gz: d4846f4dcfe771e9607266e6c1ce66a79324b7102bad2068c047072e65bb93d5bfc371b12d3dac7042d66b756e2452d7f4e14e1770b3080f1f23dd4b996bc467
6
+ metadata.gz: 9083cc7feaa8e94ac3a9bef436654d7a32e8881e201b6bfa22f6f9b8879dfdd111dc88a3643669812ed5ce8ba08d4a11a0f4a6dae576357042465bbc73b8dd89
7
+ data.tar.gz: dbb5b555a96b0f61f66a91e77c3f90b9d209a223ebf9904bad36f0e702b146e265f226a238cdf27b2abd169601203ba2faffe8742ab3090835522e4eeae20b0e
data/README.md CHANGED
@@ -119,24 +119,30 @@ You can use a regex predicate
119
119
  sequence("apple","pear").filter(matches(/app/))
120
120
  sequence(pair("apple",1),pair("pear",2)).filter(where(key:matches(/app/)))
121
121
 
122
- #### Custom Predicates
122
+ #### Custom Transformer
123
123
 
124
- Writing a custom predicate is very easy and there are 3 built in helpers:
124
+ There is a built in helper for a simple transform
125
125
 
126
- * simple_predicate
127
- * value predicate
128
- * self predicate
126
+ * simple_transform
129
127
 
130
- ##### simple_predicate
128
+ ##### simple_transform
131
129
 
132
130
  For example:
133
131
 
134
132
  def as_uppercase
135
- simple_predicate(:as_uppercase, -> (v) { v.upcase })
133
+ simple_transform(:as_uppercase, -> (v) { v.upcase })
136
134
  end
137
135
 
138
136
  sequence("apple","pear").map(as_uppercase) # returns ["APPLE","PEAR"]
139
137
 
138
+
139
+ #### Custom Predicates
140
+
141
+ Writing a custom predicate is very easy and there are 3 built in helpers:
142
+
143
+ * value predicate
144
+ * self predicate
145
+
140
146
  ##### value_predicate
141
147
 
142
148
  For example:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
data/lib/pair.rb CHANGED
@@ -48,7 +48,7 @@ module Pair
48
48
  end
49
49
 
50
50
  def self.from_map(a_map)
51
- sequence(a_map).map { |k, v| Pair.new(k, v) }
51
+ from_single(a_map).map { |k, v| Pair.new(k, v) }
52
52
  end
53
53
 
54
54
  def to_s
@@ -3,19 +3,19 @@ module Predicates
3
3
  module Conversions
4
4
 
5
5
  def as_string
6
- simple_predicate(:as_string, -> (v) { v.to_s } )
6
+ simple_transform(:as_string, -> (v) { v.to_s } )
7
7
  end
8
8
 
9
9
  def as_int
10
- simple_predicate(:as_int, -> (v) { Type.responds(v, :to_i); v.to_i } )
10
+ simple_transform(:as_int, -> (v) { Type.responds(v, :to_i); v.to_i } )
11
11
  end
12
12
 
13
13
  def as_float
14
- simple_predicate(:as_float, -> (v) { Type.responds(v, :to_f); v.to_f } )
14
+ simple_transform(:as_float, -> (v) { Type.responds(v, :to_f); v.to_f } )
15
15
  end
16
16
 
17
17
  def as_array
18
- simple_predicate(:as_array, -> (v) { [v] } )
18
+ simple_transform(:as_array, -> (v) { [v] } )
19
19
  end
20
20
 
21
21
  end
@@ -70,8 +70,8 @@ module Predicates
70
70
  SelfPredicate.new(name,pred)
71
71
  end
72
72
 
73
- def simple_predicate(name,exec)
74
- SimplePredicate.new(name,exec)
73
+ def simple_transform(name,exec)
74
+ SimpleTransform.new(name,exec)
75
75
  end
76
76
 
77
77
 
@@ -110,7 +110,7 @@ module Predicates
110
110
 
111
111
  end
112
112
 
113
- class SimplePredicate < Predicates::Predicate
113
+ class SimpleTransform < Predicates::Predicate
114
114
  attr_reader :name, :exec
115
115
 
116
116
  def initialize(name, exec)
data/lib/sequence.rb CHANGED
@@ -30,7 +30,21 @@ module Sequences
30
30
  # sequence(1,2,3).head_option # eagerly returns an option
31
31
  # some(sequence(1,2,3)).get_or_else(empty) # eagerly returns value or else empty sequence
32
32
  # sequence(1, 2, 3, 4, 5).filter(where(is greater_than 2).and(is odd)) # lazily returns 3,5
33
- def sequence(*items)
33
+ # def sequence(*items)
34
+ # if items.size == 1
35
+ # if [Range, Hash, Array, Set].include?(items.first.class)
36
+ # Sequence.new(items.first)
37
+ # elsif items.first.nil?
38
+ # empty
39
+ # else
40
+ # Sequence.new(items)
41
+ # end
42
+ # else
43
+ # Sequence.new(items)
44
+ # end
45
+ # end
46
+
47
+ def from_single(*items)
34
48
  if items.size == 1
35
49
  if [Range, Hash, Array, Set].include?(items.first.class)
36
50
  Sequence.new(items.first)
@@ -43,6 +57,15 @@ module Sequences
43
57
  Sequence.new(items)
44
58
  end
45
59
  end
60
+ module_function :from_single
61
+
62
+ def sequence(*items)
63
+ if items.first.nil?
64
+ empty
65
+ else
66
+ Sequence.new(items)
67
+ end
68
+ end
46
69
 
47
70
 
48
71
  # Creates an empty sequence
@@ -59,7 +82,7 @@ module Sequences
59
82
  end
60
83
 
61
84
  def deserialize(data)
62
- sequence(data).deserialize
85
+ from_single(data).deserialize
63
86
  end
64
87
 
65
88
  class Sequence < Enumerator
@@ -42,7 +42,7 @@ describe 'Sequence' do
42
42
  end
43
43
 
44
44
  it 'should lazily shuffle the elements - throws NoSuchElementException if empty' do
45
- expect(sequence(1..50).shuffle.entries).not_to eq(sequence(1..50).entries)
45
+ expect(from_single(1..50).shuffle.entries).not_to eq(from_single(1..50).entries)
46
46
  expect { empty.shuffle.first }.to raise_error(NoSuchElementException)
47
47
  end
48
48
 
@@ -213,7 +213,7 @@ describe 'Sequence' do
213
213
  end
214
214
 
215
215
  it 'should convert sequence to a map' do
216
- expect(sequence(oops('apple',1,'pear',2)).to_map).to eq({apple:1,pear:2})
216
+ expect(from_single(oops('apple',1,'pear',2)).to_map).to eq({apple:1,pear:2})
217
217
  end
218
218
 
219
219
  def oops(*values)
data/totally_lazy.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: totally_lazy 0.0.11 ruby lib
5
+ # stub: totally_lazy 0.0.12 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "totally_lazy"
9
- s.version = "0.0.11"
9
+ s.version = "0.0.12"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kingsley Hendrickse"]
14
- s.date = "2015-10-30"
14
+ s.date = "2015-10-31"
15
15
  s.description = "Port of java functional library totally lazy to ruby"
16
16
  s.email = "kingsleyhendrickse@me.com"
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: totally_lazy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kingsley Hendrickse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec