tbpgr_utils 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
data/.rubocop.yml CHANGED
@@ -1,2 +1,6 @@
1
+ inherit_from: rubocop-todo.yml
2
+
1
3
  LineLength:
2
- Enabled: false
4
+ Enabled: false
5
+ Semicolon:
6
+ Enabled: false
data/README.md CHANGED
@@ -24,9 +24,10 @@ Or install it yourself as:
24
24
  |[TbpgrUtils Array#together_at](#arraytogether_at) |together version of Array#at. together_at has alias :tat |
25
25
  |[TbpgrUtils Array#together_clear](#arraytogether_clear) |together version of Array#clear. together_clear has alias :tclear |
26
26
  |[TbpgrUtils Array#together_compact](#arraytogether_compact) |together version of Array#compact. together_compact has alias :tcompact. this is immutable. |
27
- |[TbpgrUtils Array#together_compact!](#arraytogether_compact!) |together version of Array#compact!. together_compact! has alias :tcompact! this is mutable. |
27
+ |[TbpgrUtils Array#together_compact!](#arraytogether_compact-1) |together version of Array#compact!. together_compact! has alias :tcompact! this is mutable. |
28
28
  |[TbpgrUtils Array#together_concat](#arraytogether_concat) |together version of Array#concat. together_concat has alias :tconcat |
29
29
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
30
+ |[TbpgrUtils Array#together_map!](#arraytogether_map-1or-tmap-1-together_collect-1-tcollect-1) |together version of Enumerable#map!. together_map! has aliases [:tmap!, :together_collect!, :tcollect!] |
30
31
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
31
32
  |[TbpgrUtils Array#together_select](#arraytogether_selector-tselect-together_find_all-tfindall) |together version of Enumerable#select. together_select has aliases [:tselect, :together_find_all, :tfindall] |
32
33
  |[TbpgrUtils Array#together_with_index](#arraytogether_with_index) |loop all arrays by block with index |
@@ -155,6 +156,37 @@ print ret # => output [["one:ret", "two:ret", "three:ret"],["1:ret", "2:ret", "3
155
156
 
156
157
  [back to list](#list)
157
158
 
159
+ ### Array#together_map!(or tmap!, together_collect!, tcollect!)
160
+ if you want to return single array, following.
161
+ ~~~ruby
162
+ require 'tbpgr_utils'
163
+
164
+ alpha = %w{one two three}
165
+ numbers = %w{1 2 3}
166
+ ary = [alpha, numbers]
167
+ ret = ary.together_map! do |first, second|
168
+ "#{first}:#{second}"
169
+ end
170
+ print ret # => output ['one:1', 'two:2', 'three:3']
171
+ print ary # => output ['one:1', 'two:2', 'three:3']
172
+ ~~~
173
+
174
+ if you want to return multi array, following.
175
+ ~~~ruby
176
+ require 'tbpgr_utils'
177
+
178
+ alpha = %w{one two three}
179
+ numbers = %w{1 2 3}
180
+ ary = [alpha, numbers]
181
+ ret = ary.together_map! do |first, second|
182
+ ["#{first}:#{second}", "#{second}:#{first}"]
183
+ end
184
+ print ret # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
185
+ print ary # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
186
+ ~~~
187
+
188
+ [back to list](#list)
189
+
158
190
  ### Array#together_reduce(or :treduce, :together_inject, :tinject)
159
191
  * if you want to single return
160
192
 
@@ -826,6 +858,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
826
858
  https://github.com/tbpgr/tbpgr_utils_snippets
827
859
 
828
860
  ## History
861
+ * version 0.0.23 : add Array#together_map!(aliases => [tmap!, together_collect!, tcollect!])
829
862
  * version 0.0.22 : add Array#together_compact. together_compact has alias :tcompact. Array#together_compact!. together_compact! has alias :tcompact!.
830
863
  * version 0.0.21 : add Array#together_clear. together_clear has alias :tclear
831
864
  * version 0.0.20 : add Array#together_at. together_at has alias :tat
@@ -1,265 +1,312 @@
1
- # encoding: utf-8
2
- require 'open_classes/object'
3
- require 'open_classes/module'
4
-
5
- # Array
6
- class Array
7
- # Arrays loop together.
8
- #
9
- # alpha = %w{one two three}
10
- # numbers = %w{1 2 3}
11
- # [alpha, numbers].together do |first, second|
12
- # print "#{first}:#{second}\n" # => output one:1, two:2, three:3
13
- # end
14
- def together
15
- if_not_contain_array_rails_type_error
16
- first.each_with_index do |i_v, i|
17
- eval_each_str = get_args_str_for_together i
18
- instance_eval "yield(#{eval_each_str})"
19
- end
20
- end
21
-
22
- # Arrays loop together with index.
23
- #
24
- # alpha = %w{one two three}
25
- # numbers = %w{1 2 3}
26
- # [alpha, numbers].together_with_index do |first, second, index|
27
- # print "#{index.to_s}:#{first}:#{second}\n" # => output 0:one:1, 1:two:2, 2:three:3
28
- # end
29
- def together_with_index
30
- if_not_contain_array_rails_type_error
31
- first.each_with_index do |i_v, i|
32
- eval_each_str = get_args_str_for_together i, true
33
- instance_eval "yield(#{eval_each_str})"
34
- end
35
- end
36
-
37
- # Arrays together map.
38
- #
39
- # together_map has aliases [:tmap, :together_collect, :tcollect]
40
- #
41
- # if you want to single Array return
42
- # alpha = %w{one two three}
43
- # numbers = %w{1 2 3}
44
- # print [alpha, numbers].together_map do |first, second|
45
- # "#{first}:#{second}\n"
46
- # end # => output one:1, two:2, three:3
47
- #
48
- # if you want to multi Array return
49
- # alpha = %w{one two three}
50
- # numbers = %w{1 2 3}
51
- # print [alpha, numbers].together_map do |first, second|
52
- # ["#{first}:#{second}", "#{second}:#{first}"]
53
- # end # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
54
- def together_map
55
- if_not_contain_array_rails_type_error
56
- ret = []
57
- first.each_with_index do |i_v, i|
58
- eval_each_str = get_args_str_for_together i
59
- each_ret = instance_eval "yield(#{eval_each_str})"
60
- ret = set_together_each_return_map(ret, each_ret, i)
61
- end
62
- ret
63
- end
64
-
65
- # Arrays loop together select.
66
- #
67
- # together_select has aliases [:tselect, :together_find_all, :tfindall]
68
- #
69
- # if you want to single Array return
70
- # firsts = [1, 2, 3, 4]
71
- # seconds = [4, 2, 3, 1]
72
- # ret = [firsts, seconds].together_select{|first, second|first == second}
73
- # print ret # => output [[2, 3], [2, 3]]
74
- #
75
- # if you want to multi Array return
76
- # firsts = [1, 2, 3, 4]
77
- # seconds = [4, 2, 3, 1]
78
- # ret = [firsts, seconds].together_select{|first, second|[first.odd?, second.even?]}
79
- # print ret # => output [[1, 3], [4, 2]]
80
- def together_select
81
- if_not_contain_array_rails_type_error
82
- ret = []
83
- first.each_with_index do |i_v, i|
84
- eval_each_str = get_args_str_for_together i
85
- each_ret = instance_eval "yield(#{eval_each_str})"
86
- ret = set_together_each_return_select(ret, each_ret, i)
87
- end
88
- ret
89
- end
90
-
91
- # Arrays loop together reduce.
92
- #
93
- # together_reduce has aliases [:treduce, :together_inject, :tinject]
94
- #
95
- # if you want to single return
96
- # firsts = [1, 2, 3, 4]
97
- # seconds = [4, 2, 3, 1]
98
- # ret = [firsts, seconds].together_reduce{|memo, first, second|memo + first + second}
99
- # print ret # => output 20
100
- #
101
- # if you want to single return with init value
102
- # firsts = [1, 2, 3, 4]
103
- # seconds = [4, 2, 3, 1]
104
- # ret = [firsts, seconds].together_reduce(10){|memo, first, second|memo + first + second}
105
- # print ret # => output 30
106
- #
107
- # if you want to single return with init string value
108
- # firsts = %w{a b c}
109
- # seconds = %w{1 2 3}
110
- # ret = [firsts, seconds].together_reduce('start-'){|memo, first, second|memo + first + second}
111
- # print ret # => output 'start-a1b2c3'
112
- #
113
- # if you want to single return with init Array value
114
- # firsts = [1, 2, 3, 4]
115
- # seconds = [4, 2, 3, 1]
116
- # ret = [firsts, seconds].together_reduce([]){|memo, first, second|memo << first + second}
117
- # print ret # => output [5, 4, 6, 5]
118
- #
119
- # if you want to single return with init Hash value
120
- # firsts = [1, 2, 3, 4]
121
- # seconds = [4, 2, 3, 1]
122
- # ret = [firsts, seconds].together_reduce({}){|memo, first, second|memo[first] = second;memo}
123
- # print ret # => output {1=>4, 2=>2, 3=>3, 4=>1}
124
- def together_reduce(init = nil)
125
- if_not_contain_array_rails_type_error
126
- memo = initial_memo init
127
- first.each_with_index do |i_v, i|
128
- eval_each_str = get_args_str_for_together i
129
- memo = instance_eval "yield(memo, #{eval_each_str})"
130
- end
131
- memo
132
- end
133
-
134
- # Arrays bulk concat.
135
- #
136
- # together_concat has alias :tconcat
137
- #
138
- # alpha = %w{one two three}
139
- # numbers = %w{1 2 3}
140
- # [alpha, numbers].together do |first, second|
141
- # print "#{first}:#{second}\n" # => output one:1, two:2, three:3
142
- # end
143
- def together_concat(other)
144
- if_not_contain_array_rails_type_error
145
- each { |list|list.concat other }
146
- end
147
-
148
- # Arrays bulk at.
149
- #
150
- # together_at has alias :tat
151
- #
152
- # same elements size case
153
- # alpha = %w{one two three}
154
- # numbers = %w{1 2 3}
155
- # [alpha, numbers].together_at 2 # => output ['three', 3]
156
- #
157
- # different elements size case
158
- # alpha = %w{one two three}
159
- # numbers = %w{1 2}
160
- # [alpha, numbers].together_at 2 # => output ['three', nil]
161
- def together_at(index)
162
- if_not_contain_array_rails_type_error
163
- reduce([]) { |ats, list|ats << list.at(index) }
164
- end
165
-
166
- # Arrays bulk clear.
167
- #
168
- # together_clear has alias :tclear
169
- #
170
- # same elements size case
171
- # alpha = %w{one two three}
172
- # numbers = %w{1 2 3}
173
- # [alpha, numbers].together_clear # => output [[],[]]
174
- def together_clear
175
- if_not_contain_array_rails_type_error
176
- each { |list|list.clear }
177
- end
178
-
179
- # Arrays bulk compact.(immutable)
180
- #
181
- # together_compact has alias :tcompact
182
- #
183
- # same elements size case
184
- # alpha = ['a','b','c', nil,'d']
185
- # numbers = [1, 2, nil, 3]
186
- # lists = [alpha, numbers]
187
- # ret = lists.together_compact
188
- # print lists # => output [['a','b','c', nil,'d'], [1, 2, nil, 3]]
189
- # print ret # => output [['a','b','c','d'], [1, 2, 3]]
190
- def together_compact
191
- if_not_contain_array_rails_type_error
192
- reduce([]) { |ret, list|ret << list.compact }
193
- end
194
-
195
- # Arrays bulk compact!.(mutable)
196
- #
197
- # together_compact! has alias :tcompact!
198
- #
199
- # same elements size case
200
- # alpha = ['a','b','c', nil,'d']
201
- # numbers = [1, 2, nil, 3]
202
- # ret = lists.together_compact!
203
- # print lists # => output [['a','b','c','d'], [1, 2, 3]]
204
- # print ret # => output [['a','b','c','d'], [1, 2, 3]]
205
- def together_compact!
206
- if_not_contain_array_rails_type_error
207
- each { |list|list.compact! }
208
- end
209
-
210
- private
211
-
212
- def if_not_contain_array_rails_type_error
213
- each { |f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array }
214
- end
215
-
216
- def get_args_for_together(i)
217
- eval_each = []
218
- each_with_index { |j_v, j|eval_each << "self[#{j}][#{i}]" }
219
- eval_each
220
- end
221
-
222
- def get_args_str_for_together(i, with_index = false)
223
- each_eval = with_index ? get_args_for_together(i) << i : get_args_for_together(i)
224
- each_eval.join(',')
225
- end
226
-
227
- def set_together_each_return_map(ret, each_ret, index)
228
- if together_return_multi?(each_ret)
229
- size.times { |i|ret << [] } if index == 0
230
- (0..(size - 1)).each { |i|ret[i] << each_ret[i] }
231
- else
232
- ret << each_ret
233
- end
234
- ret
235
- end
236
-
237
- def set_together_each_return_select(ret, each_ret, index)
238
- unless together_return_multi?(each_ret)
239
- tmp_each_ret = []
240
- size.times { tmp_each_ret << each_ret }
241
- each_ret = tmp_each_ret
242
- end
243
- size.times { |i|ret << [] } if index == 0
244
- (0..(size - 1)).each { |i|ret[i] << self[i][index] if each_ret[i] }
245
- ret
246
- end
247
-
248
- def initial_memo(init)
249
- return init unless init.nil?
250
- first.first.is_a?(Numeric) ? 0 : first.first.is_a?(String) ? '' : nil
251
- end
252
-
253
- def together_return_multi?(list)
254
- (list.class == Array && list.size == size).to_bool
255
- end
256
-
257
- alias_method :tconcat, :together_concat
258
- alias_method :tat, :together_at
259
- alias_method :tclear, :together_clear
260
- alias_method :tcompact, :together_compact
261
- alias_method :tcompact!, :together_compact!
262
- alias_methods [:together_collect, :tmap, :tcollect], :together_map
263
- alias_methods [:together_find_all, :tselect, :tfindall], :together_select
264
- alias_methods [:together_inject, :treduce, :tinject], :together_reduce
265
- end
1
+ # encoding: utf-8
2
+ require 'open_classes/object'
3
+ require 'open_classes/module'
4
+
5
+ # Array
6
+ class Array
7
+ # Arrays loop together.
8
+ #
9
+ # alpha = %w{one two three}
10
+ # numbers = %w{1 2 3}
11
+ # [alpha, numbers].together do |first, second|
12
+ # print "#{first}:#{second}\n" # => output one:1, two:2, three:3
13
+ # end
14
+ def together
15
+ if_not_contain_array_rails_type_error
16
+ first.each_with_index do |i_v, i|
17
+ eval_each_str = get_args_str_for_together i
18
+ instance_eval "yield(#{eval_each_str})"
19
+ end
20
+ end
21
+
22
+ # Arrays loop together with index.
23
+ #
24
+ # alpha = %w{one two three}
25
+ # numbers = %w{1 2 3}
26
+ # [alpha, numbers].together_with_index do |first, second, index|
27
+ # print "#{index.to_s}:#{first}:#{second}\n" # => output 0:one:1, 1:two:2, 2:three:3
28
+ # end
29
+ def together_with_index
30
+ if_not_contain_array_rails_type_error
31
+ first.each_with_index do |i_v, i|
32
+ eval_each_str = get_args_str_for_together i, true
33
+ instance_eval "yield(#{eval_each_str})"
34
+ end
35
+ end
36
+
37
+ # Arrays together map.
38
+ #
39
+ # together_map has aliases [:tmap, :together_collect, :tcollect]
40
+ #
41
+ # if you want to single Array return
42
+ # alpha = %w{one two three}
43
+ # numbers = %w{1 2 3}
44
+ # print [alpha, numbers].together_map do |first, second|
45
+ # "#{first}:#{second}\n"
46
+ # end # => output one:1, two:2, three:3
47
+ #
48
+ # if you want to multi Array return
49
+ # alpha = %w{one two three}
50
+ # numbers = %w{1 2 3}
51
+ # print [alpha, numbers].together_map do |first, second|
52
+ # ["#{first}:#{second}", "#{second}:#{first}"]
53
+ # end # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
54
+ def together_map
55
+ if_not_contain_array_rails_type_error
56
+ ret = []
57
+ first.each_with_index do |i_v, i|
58
+ eval_each_str = get_args_str_for_together i
59
+ each_ret = instance_eval "yield(#{eval_each_str})"
60
+ ret = set_together_each_return_map(ret, each_ret, i)
61
+ end
62
+ ret
63
+ end
64
+
65
+
66
+ # Arrays together map!.
67
+ #
68
+ # together_map! has aliases [:tmap!, :together_collect!, :tcollect!]
69
+ #
70
+ # if you want to single Array return
71
+ # alpha = %w{one two three}
72
+ # numbers = %w{1 2 3}
73
+ # ary = [alpha, numbers]
74
+ # ret = ary.together_map! do |first, second|
75
+ # "#{first}:#{second}"
76
+ # end
77
+ # print ret # => output ['one:1', 'two:2', 'three:3']
78
+ # print ary # => output ['one:1', 'two:2', 'three:3']
79
+ #
80
+ # if you want to multi Array return
81
+ # alpha = %w{one two three}
82
+ # numbers = %w{1 2 3}
83
+ # ary = [alpha, numbers]
84
+ # ret = ary.together_map! do |first, second|
85
+ # ["#{first}:#{second}", "#{second}:#{first}"]
86
+ # end
87
+ # print ret # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
88
+ # print ary # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
89
+ def together_map!
90
+ if_not_contain_array_rails_type_error
91
+ ret = []
92
+ first.each_with_index do |i_v, i|
93
+ eval_each_str = get_args_str_for_together i
94
+ each_ret = instance_eval "yield(#{eval_each_str})"
95
+ ret = set_together_each_return_map(ret, each_ret, i)
96
+ end
97
+ clear
98
+ ret.each { |v|self << v }
99
+ end
100
+
101
+ # Arrays loop together select.
102
+ #
103
+ # together_select has aliases [:tselect, :together_find_all, :tfindall]
104
+ #
105
+ # if you want to single Array return
106
+ # firsts = [1, 2, 3, 4]
107
+ # seconds = [4, 2, 3, 1]
108
+ # ret = [firsts, seconds].together_select{|first, second|first == second}
109
+ # print ret # => output [[2, 3], [2, 3]]
110
+ #
111
+ # if you want to multi Array return
112
+ # firsts = [1, 2, 3, 4]
113
+ # seconds = [4, 2, 3, 1]
114
+ # ret = [firsts, seconds].together_select{|first, second|[first.odd?, second.even?]}
115
+ # print ret # => output [[1, 3], [4, 2]]
116
+ def together_select
117
+ if_not_contain_array_rails_type_error
118
+ ret = []
119
+ first.each_with_index do |i_v, i|
120
+ eval_each_str = get_args_str_for_together i
121
+ each_ret = instance_eval "yield(#{eval_each_str})"
122
+ ret = set_together_each_return_select(ret, each_ret, i)
123
+ end
124
+ ret
125
+ end
126
+
127
+ # Arrays loop together reduce.
128
+ #
129
+ # together_reduce has aliases [:treduce, :together_inject, :tinject]
130
+ #
131
+ # if you want to single return
132
+ # firsts = [1, 2, 3, 4]
133
+ # seconds = [4, 2, 3, 1]
134
+ # ret = [firsts, seconds].together_reduce{|memo, first, second|memo + first + second}
135
+ # print ret # => output 20
136
+ #
137
+ # if you want to single return with init value
138
+ # firsts = [1, 2, 3, 4]
139
+ # seconds = [4, 2, 3, 1]
140
+ # ret = [firsts, seconds].together_reduce(10){|memo, first, second|memo + first + second}
141
+ # print ret # => output 30
142
+ #
143
+ # if you want to single return with init string value
144
+ # firsts = %w{a b c}
145
+ # seconds = %w{1 2 3}
146
+ # ret = [firsts, seconds].together_reduce('start-'){|memo, first, second|memo + first + second}
147
+ # print ret # => output 'start-a1b2c3'
148
+ #
149
+ # if you want to single return with init Array value
150
+ # firsts = [1, 2, 3, 4]
151
+ # seconds = [4, 2, 3, 1]
152
+ # ret = [firsts, seconds].together_reduce([]){|memo, first, second|memo << first + second}
153
+ # print ret # => output [5, 4, 6, 5]
154
+ #
155
+ # if you want to single return with init Hash value
156
+ # firsts = [1, 2, 3, 4]
157
+ # seconds = [4, 2, 3, 1]
158
+ # ret = [firsts, seconds].together_reduce({}){|memo, first, second|memo[first] = second;memo}
159
+ # print ret # => output {1=>4, 2=>2, 3=>3, 4=>1}
160
+ def together_reduce(init = nil)
161
+ if_not_contain_array_rails_type_error
162
+ memo = initial_memo init
163
+ first.each_with_index do |i_v, i|
164
+ eval_each_str = get_args_str_for_together i
165
+ memo = instance_eval "yield(memo, #{eval_each_str})"
166
+ end
167
+ memo
168
+ end
169
+
170
+ # Arrays bulk concat.
171
+ #
172
+ # together_concat has alias :tconcat
173
+ #
174
+ # alpha = %w{one two three}
175
+ # numbers = %w{1 2 3}
176
+ # [alpha, numbers].together do |first, second|
177
+ # print "#{first}:#{second}\n" # => output one:1, two:2, three:3
178
+ # end
179
+ def together_concat(other)
180
+ if_not_contain_array_rails_type_error
181
+ each { |list|list.concat other }
182
+ end
183
+
184
+ # Arrays bulk at.
185
+ #
186
+ # together_at has alias :tat
187
+ #
188
+ # same elements size case
189
+ # alpha = %w{one two three}
190
+ # numbers = %w{1 2 3}
191
+ # [alpha, numbers].together_at 2 # => output ['three', 3]
192
+ #
193
+ # different elements size case
194
+ # alpha = %w{one two three}
195
+ # numbers = %w{1 2}
196
+ # [alpha, numbers].together_at 2 # => output ['three', nil]
197
+ def together_at(index)
198
+ if_not_contain_array_rails_type_error
199
+ reduce([]) { |ats, list|ats << list.at(index) }
200
+ end
201
+
202
+ # Arrays bulk clear.
203
+ #
204
+ # together_clear has alias :tclear
205
+ #
206
+ # same elements size case
207
+ # alpha = %w{one two three}
208
+ # numbers = %w{1 2 3}
209
+ # [alpha, numbers].together_clear # => output [[],[]]
210
+ def together_clear
211
+ if_not_contain_array_rails_type_error
212
+ each { |list|list.clear }
213
+ end
214
+
215
+ # Arrays bulk compact.(immutable)
216
+ #
217
+ # together_compact has alias :tcompact
218
+ #
219
+ # same elements size case
220
+ # alpha = ['a','b','c', nil,'d']
221
+ # numbers = [1, 2, nil, 3]
222
+ # lists = [alpha, numbers]
223
+ # ret = lists.together_compact
224
+ # print lists # => output [['a','b','c', nil,'d'], [1, 2, nil, 3]]
225
+ # print ret # => output [['a','b','c','d'], [1, 2, 3]]
226
+ def together_compact
227
+ if_not_contain_array_rails_type_error
228
+ reduce([]) { |ret, list|ret << list.compact }
229
+ end
230
+
231
+ # Arrays bulk compact!.(mutable)
232
+ #
233
+ # together_compact! has alias :tcompact!
234
+ #
235
+ # same elements size case
236
+ # alpha = ['a','b','c', nil,'d']
237
+ # numbers = [1, 2, nil, 3]
238
+ # ret = lists.together_compact!
239
+ # print lists # => output [['a','b','c','d'], [1, 2, 3]]
240
+ # print ret # => output [['a','b','c','d'], [1, 2, 3]]
241
+ def together_compact!
242
+ if_not_contain_array_rails_type_error
243
+ each { |list|list.compact! }
244
+ end
245
+
246
+ private
247
+
248
+ def if_not_contain_array_rails_type_error
249
+ each { |f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array }
250
+ end
251
+
252
+ def get_args_for_together(i)
253
+ eval_each = []
254
+ each_with_index { |j_v, j|eval_each << "self[#{j}][#{i}]" }
255
+ eval_each
256
+ end
257
+
258
+ def get_args_str_for_together(i, with_index = false)
259
+ each_eval = with_index ? get_args_for_together(i) << i : get_args_for_together(i)
260
+ each_eval.join(',')
261
+ end
262
+
263
+ def set_together_each_return_map(ret, each_ret, index)
264
+ if together_return_multi?(each_ret)
265
+ size.times { |i|ret << [] } if index == 0
266
+ (0..(size - 1)).each { |i|ret[i] << each_ret[i] }
267
+ else
268
+ ret << each_ret
269
+ end
270
+ ret
271
+ end
272
+
273
+ # def set_together_each_return_map!(ret, each_ret, index)
274
+ # if together_return_multi?(each_ret)
275
+ # size.times { |i|ret << [] } if index == 0
276
+ # (0..(size - 1)).each { |i|ret[i] each_ret[i] }
277
+ # else
278
+ # ret << each_ret
279
+ # end
280
+ # ret
281
+ # end
282
+
283
+ def set_together_each_return_select(ret, each_ret, index)
284
+ unless together_return_multi?(each_ret)
285
+ tmp_each_ret = []
286
+ size.times { tmp_each_ret << each_ret }
287
+ each_ret = tmp_each_ret
288
+ end
289
+ size.times { |i|ret << [] } if index == 0
290
+ (0..(size - 1)).each { |i|ret[i] << self[i][index] if each_ret[i] }
291
+ ret
292
+ end
293
+
294
+ def initial_memo(init)
295
+ return init unless init.nil?
296
+ first.first.is_a?(Numeric) ? 0 : first.first.is_a?(String) ? '' : nil
297
+ end
298
+
299
+ def together_return_multi?(list)
300
+ (list.class == Array && list.size == size).to_bool
301
+ end
302
+
303
+ alias_method :tconcat, :together_concat
304
+ alias_method :tat, :together_at
305
+ alias_method :tclear, :together_clear
306
+ alias_method :tcompact, :together_compact
307
+ alias_method :tcompact!, :together_compact!
308
+ alias_methods [:together_collect, :tmap, :tcollect], :together_map
309
+ alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
310
+ alias_methods [:together_find_all, :tselect, :tfindall], :together_select
311
+ alias_methods [:together_inject, :treduce, :tinject], :together_reduce
312
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.22'
5
+ VERSION = '0.0.23'
6
6
  end