rudash 2.17.1 → 2.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rudash/at.rb +8 -8
- data/lib/rudash/capitalize.rb +4 -4
- data/lib/rudash/chain.rb +4 -4
- data/lib/rudash/compact.rb +5 -5
- data/lib/rudash/concat.rb +9 -9
- data/lib/rudash/curry.rb +4 -4
- data/lib/rudash/difference.rb +11 -11
- data/lib/rudash/drop_right.rb +9 -9
- data/lib/rudash/each.rb +8 -8
- data/lib/rudash/each_right.rb +10 -10
- data/lib/rudash/eq.rb +4 -4
- data/lib/rudash/every.rb +5 -5
- data/lib/rudash/filter.rb +23 -23
- data/lib/rudash/find.rb +7 -7
- data/lib/rudash/find_last.rb +7 -7
- data/lib/rudash/flip.rb +10 -10
- data/lib/rudash/flow.rb +11 -11
- data/lib/rudash/flow_right.rb +6 -6
- data/lib/rudash/get.rb +22 -22
- data/lib/rudash/group_by.rb +17 -17
- data/lib/rudash/head.rb +8 -8
- data/lib/rudash/identity.rb +4 -4
- data/lib/rudash/initial.rb +6 -6
- data/lib/rudash/intersection.rb +10 -10
- data/lib/rudash/is_array.rb +4 -4
- data/lib/rudash/is_empty.rb +9 -9
- data/lib/rudash/is_equal.rb +4 -4
- data/lib/rudash/is_hash.rb +4 -4
- data/lib/rudash/is_nil.rb +4 -4
- data/lib/rudash/is_number.rb +4 -4
- data/lib/rudash/is_string.rb +4 -4
- data/lib/rudash/join.rb +6 -6
- data/lib/rudash/keys.rb +11 -11
- data/lib/rudash/last.rb +5 -5
- data/lib/rudash/map.rb +19 -19
- data/lib/rudash/negate.rb +8 -8
- data/lib/rudash/pick.rb +16 -16
- data/lib/rudash/range.rb +43 -43
- data/lib/rudash/reduce.rb +29 -29
- data/lib/rudash/reduce_right.rb +5 -5
- data/lib/rudash/reject.rb +13 -13
- data/lib/rudash/remove.rb +9 -9
- data/lib/rudash/reverse.rb +9 -9
- data/lib/rudash/set.rb +20 -20
- data/lib/rudash/size.rb +5 -5
- data/lib/rudash/slice.rb +12 -12
- data/lib/rudash/some.rb +5 -5
- data/lib/rudash/tail.rb +5 -5
- data/lib/rudash/take.rb +11 -11
- data/lib/rudash/union.rb +15 -15
- data/lib/rudash/uniq.rb +11 -11
- data/lib/rudash/unset.rb +30 -30
- data/lib/rudash/update.rb +9 -9
- data/lib/rudash/without.rb +5 -5
- data/lib/rudash.rb +54 -54
- data/lib/utils/chain_wrapper.rb +18 -18
- data/lib/utils/dynamic_args_count.rb +10 -10
- data/lib/utils/index.rb +17 -17
- data/lib/utils/nested_path_creator.rb +24 -24
- data/lib/utils/path_resolver.rb +17 -17
- data/lib/utils/subset_deep_match.rb +41 -41
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77e2032efa0ddf9ce5dbeca618a4abeb9784604e1eda780a2a631a5007d69944
|
4
|
+
data.tar.gz: c4d8634e037a06d83629ed8a4f779c7820401ed2fc11c3b9e2750e3e1525a03c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d40799aaff249470c2ca687b4940dc3e2c83cbb844ad127fd295673facfeaf86d84248345160358c19f34251b7f00a3568196ea80be2942ffb2c43cc2d22353
|
7
|
+
data.tar.gz: 0a578b3d96e1526795282ab6202c0aaadce2a4acbc6d0cdb98206a2947bfaf1a87076ea6069025f5171ef6f293c36ddace1f15ba09ce040d871e7028956e595b
|
data/lib/rudash/at.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
2
|
+
module At
|
3
|
+
def at(object, paths)
|
4
|
+
get_mapper = -> (path) {
|
5
|
+
self.get(object, path)
|
6
|
+
}
|
7
|
+
|
8
|
+
self.map(paths, get_mapper)
|
10
9
|
end
|
10
|
+
end
|
11
11
|
end
|
data/lib/rudash/capitalize.rb
CHANGED
data/lib/rudash/chain.rb
CHANGED
data/lib/rudash/compact.rb
CHANGED
data/lib/rudash/concat.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
2
|
+
module Concat
|
3
|
+
def concat(head, *values)
|
4
|
+
head_arr = head.is_a?(Array) ? head : [head]
|
5
|
+
if values.size == 0
|
6
|
+
return head_arr
|
7
|
+
else
|
8
|
+
return head_arr + self.concat(*values)
|
9
|
+
end
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/curry.rb
CHANGED
data/lib/rudash/difference.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
module Difference
|
3
|
+
def difference(*values)
|
4
|
+
diff_reducer = -> (acc, current) {
|
5
|
+
return [] if !acc.is_a?(Array)
|
6
|
+
return acc if !current.is_a?(Array)
|
7
|
+
|
8
|
+
acc - current
|
9
|
+
}
|
10
|
+
|
11
|
+
self.reduce(values, diff_reducer)
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|
data/lib/rudash/drop_right.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
2
|
+
module DropRight
|
3
|
+
def drop_right(array, *rest_args)
|
4
|
+
return [] if !self.is_array?(array)
|
5
|
+
|
6
|
+
n = self.head(rest_args) || 1
|
7
|
+
return array if n <= 0
|
8
|
+
|
9
|
+
self.take(array, self.size(array) - n)
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/each.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
module Each
|
3
|
+
def each(collection, *rest_args)
|
4
|
+
self.map(collection, *rest_args)
|
5
|
+
collection
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
def for_each(*args)
|
9
|
+
self.each(*args)
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/each_right.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
module EachRight
|
3
|
+
def each_right(collection, *rest_args)
|
4
|
+
reversed_collection = Rudash::Utils.force_reverse(collection)
|
5
|
+
|
6
|
+
self.each(reversed_collection, *rest_args)
|
7
|
+
collection
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
10
|
+
def for_each_right(*args)
|
11
|
+
self.each_right(*args)
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|
data/lib/rudash/eq.rb
CHANGED
data/lib/rudash/every.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
module Every
|
3
|
+
def every?(array, filter)
|
4
|
+
filtered_arr = self.filter(array, filter)
|
5
|
+
filtered_arr.length == array.length
|
7
6
|
end
|
7
|
+
end
|
8
8
|
end
|
data/lib/rudash/filter.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
2
|
+
module Filter
|
3
|
+
def filter(collection, *rest_args)
|
4
|
+
predicate_fn = self.head(rest_args) || self.method(:identity)
|
5
|
+
|
6
|
+
if predicate_fn.is_a?(Hash)
|
7
|
+
slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(predicate_fn)
|
8
|
+
return self.filter(collection, slice_matcher)
|
9
|
+
end
|
10
|
+
|
11
|
+
return [] if !Rudash::Utils.is_function?(predicate_fn)
|
12
|
+
|
13
|
+
if collection.is_a?(Array)
|
14
|
+
return collection.select.with_index { |x, idx|
|
15
|
+
Rudash::DynamicArgsCount.call(predicate_fn, x, idx)
|
16
|
+
}
|
17
|
+
elsif collection.is_a?(Hash)
|
18
|
+
return collection.select { |k, v|
|
19
|
+
Rudash::DynamicArgsCount.call(predicate_fn, v, k)
|
20
|
+
}.values
|
21
|
+
else
|
22
|
+
return []
|
23
|
+
end
|
25
24
|
end
|
25
|
+
end
|
26
26
|
end
|
data/lib/rudash/find.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
2
|
+
module Find
|
3
|
+
def find(collection, *rest_args)
|
4
|
+
iteratee_fn = self.head(rest_args)
|
5
|
+
filtered_arr = self.filter(collection, iteratee_fn)
|
6
|
+
|
7
|
+
filtered_arr[0]
|
9
8
|
end
|
9
|
+
end
|
10
10
|
end
|
data/lib/rudash/find_last.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
2
|
+
module FindLast
|
3
|
+
def find_last(collection, *rest_args)
|
4
|
+
iteratee_fn = self.head(rest_args)
|
5
|
+
filtered_arr = self.filter(collection, iteratee_fn)
|
6
|
+
|
7
|
+
filtered_arr[filtered_arr.length - 1]
|
9
8
|
end
|
9
|
+
end
|
10
10
|
end
|
data/lib/rudash/flip.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
2
|
+
module Flip
|
3
|
+
def flip(a_proc)
|
4
|
+
raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
|
5
|
+
|
6
|
+
flipped_proc = -> (*args) {
|
7
|
+
reveresed_args = args.reverse
|
8
|
+
|
9
|
+
a_proc.(*reveresed_args)
|
10
|
+
}
|
12
11
|
end
|
12
|
+
end
|
13
13
|
end
|
data/lib/rudash/flow.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
module Flow
|
3
|
+
def flow(*funs)
|
4
|
+
flatten_funs = funs.flatten
|
5
|
+
|
6
|
+
flow_proc = -> (*args) {
|
7
|
+
self.reduce(flatten_funs, -> (acc, fn) {
|
8
|
+
Rudash::DynamicArgsCount.call(fn, *self.concat(acc))
|
9
|
+
}, args)
|
10
|
+
}
|
11
|
+
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/lib/rudash/flow_right.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
module FlowRight
|
3
|
+
def flow_right(*funs)
|
4
|
+
flatten_funs = funs.flatten.reverse
|
5
|
+
|
6
|
+
self.flow(flatten_funs)
|
8
7
|
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/rudash/get.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
self.reduce(resolved_path, get_reducer, hash)
|
2
|
+
module Get
|
3
|
+
def get(hash, path, *rest_args)
|
4
|
+
return nil if !path.is_a?(String) && !path.is_a?(Array)
|
5
|
+
return nil if !hash.is_a?(Array) && !hash.is_a?(Hash)
|
6
|
+
|
7
|
+
resolved_path = Rudash::PathResolver.resolve(path)
|
8
|
+
|
9
|
+
get_reducer = -> (acc, current) {
|
10
|
+
return nil if acc.nil?
|
11
|
+
|
12
|
+
if acc.is_a?(Array) && Rudash::Utils.match_number?(current)
|
13
|
+
acc[current.to_i]
|
14
|
+
elsif acc.is_a?(Array) && !Rudash::Utils.match_number?(current)
|
15
|
+
nil
|
16
|
+
elsif acc.is_a?(Hash)
|
17
|
+
acc[current.to_sym] || acc[current]
|
18
|
+
else
|
19
|
+
nil
|
24
20
|
end
|
21
|
+
}
|
22
|
+
|
23
|
+
self.reduce(resolved_path, get_reducer, hash)
|
25
24
|
end
|
25
|
+
end
|
26
26
|
end
|
data/lib/rudash/group_by.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
acc
|
16
|
-
}
|
17
|
-
|
18
|
-
self.reduce(collection, reducer, {})
|
2
|
+
module GroupBy
|
3
|
+
def group_by(collection, *rest_args)
|
4
|
+
iteratee = self.head(rest_args) || self.method(:identity)
|
5
|
+
|
6
|
+
reducer = -> (acc, current) {
|
7
|
+
key = Rudash::DynamicArgsCount.call(iteratee, current)
|
8
|
+
|
9
|
+
if acc[key]
|
10
|
+
acc[key] << current
|
11
|
+
else
|
12
|
+
acc[key] = [current]
|
19
13
|
end
|
14
|
+
|
15
|
+
acc
|
16
|
+
}
|
17
|
+
|
18
|
+
self.reduce(collection, reducer, {})
|
20
19
|
end
|
20
|
+
end
|
21
21
|
end
|
data/lib/rudash/head.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
module Head
|
3
|
+
def head(array)
|
4
|
+
return nil if !array.is_a?(Array)
|
5
|
+
array.first
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
def first(*args)
|
9
|
+
self.head(*args)
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/identity.rb
CHANGED
data/lib/rudash/initial.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
module Initial
|
3
|
+
def initial(array)
|
4
|
+
return [] if !array.is_a?(Array)
|
5
|
+
*initial, last = array
|
6
|
+
initial
|
8
7
|
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/rudash/intersection.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
2
|
+
module Intersection
|
3
|
+
def intersection(*values)
|
4
|
+
|
5
|
+
intersection_reducer = -> (acc, current) {
|
6
|
+
return [] if !current.is_a?(Array) || !acc.is_a?(Array)
|
7
|
+
acc & current
|
8
|
+
}
|
9
|
+
|
10
|
+
self.reduce(values, intersection_reducer, values[0])
|
12
11
|
end
|
12
|
+
end
|
13
13
|
end
|
data/lib/rudash/is_array.rb
CHANGED
data/lib/rudash/is_empty.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
2
|
+
module IsEmpty
|
3
|
+
def is_empty?(value)
|
4
|
+
case value
|
5
|
+
when Hash, Array
|
6
|
+
value.empty?
|
7
|
+
else
|
8
|
+
true
|
9
|
+
end
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/is_equal.rb
CHANGED
data/lib/rudash/is_hash.rb
CHANGED
data/lib/rudash/is_nil.rb
CHANGED
data/lib/rudash/is_number.rb
CHANGED