ramda-ruby 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/ROADMAP.md +0 -11
- data/docs/FUNCTIONS.md +10 -0
- data/lib/ramda.rb +10 -1
- data/lib/ramda/function.rb +55 -0
- data/lib/ramda/internal/curried_method.rb +3 -0
- data/lib/ramda/internal/function_with_arity.rb +7 -7
- data/lib/ramda/list.rb +45 -0
- data/lib/ramda/math.rb +6 -0
- data/lib/ramda/type.rb +12 -0
- data/lib/ramda/version.rb +1 -1
- data/spec/ramda/function_spec.rb +33 -0
- data/spec/ramda/internal/curried_method_spec.rb +1 -0
- data/spec/ramda/list_spec.rb +55 -0
- data/spec/ramda/logic_spec.rb +6 -6
- data/spec/ramda/math_spec.rb +16 -0
- data/spec/ramda/object_spec.rb +2 -2
- data/spec/ramda/type_spec.rb +26 -0
- data/spec/ramda_spec.rb +13 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5069f465457b70d73fdf3293e664aed146961a04
|
4
|
+
data.tar.gz: d92e10b760d7774df9ae4adfabbb4e16815a9850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51cb3c50f9b3210f0cc362548839746481e14729f8e70b526475148fc0d7454d2be8e65a7a60b7fb8f7449a74d2efa35d85fc504039d99cc0947971754ba691c
|
7
|
+
data.tar.gz: 9e425cf05c7667634c5e175e46fcb645b0dd7b57ad340c4a30f93bdd9198942c4f1a140aa6a8ebf7a585211b2ff468f575135c56735b9040b5a4cd66ec3bc926
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
Not Released
|
2
2
|
---------------
|
3
3
|
|
4
|
+
Release 0.3.0
|
5
|
+
---------------
|
6
|
+
|
7
|
+
* (pending) math_mod
|
8
|
+
* ap
|
9
|
+
* chain
|
10
|
+
* complement
|
11
|
+
* empty - uses x.class.new for defining new empty object if empty method does not exist
|
12
|
+
* from_pairs
|
13
|
+
* is
|
14
|
+
* of
|
15
|
+
* unnest
|
16
|
+
* zip_obj
|
17
|
+
|
4
18
|
Release 0.2.3
|
5
19
|
---------------
|
6
20
|
|
data/ROADMAP.md
CHANGED
data/docs/FUNCTIONS.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
* (pending) keys_in
|
2
|
+
* (pending) math_mod
|
2
3
|
* (pending) values_in
|
3
4
|
* add
|
4
5
|
* all
|
@@ -7,11 +8,14 @@
|
|
7
8
|
* and
|
8
9
|
* any
|
9
10
|
* any_pass
|
11
|
+
* ap
|
10
12
|
* append
|
11
13
|
* assoc
|
12
14
|
* binary
|
15
|
+
* chain
|
13
16
|
* clone
|
14
17
|
* comparator
|
18
|
+
* complement
|
15
19
|
* compose
|
16
20
|
* concat
|
17
21
|
* construct
|
@@ -25,6 +29,7 @@
|
|
25
29
|
* dissoc
|
26
30
|
* divide
|
27
31
|
* drop
|
32
|
+
* empty - uses x.class.new for defining new empty object if empty method does not exist
|
28
33
|
* eq_by
|
29
34
|
* eq_props
|
30
35
|
* equals
|
@@ -36,6 +41,7 @@
|
|
36
41
|
* flatten
|
37
42
|
* flip
|
38
43
|
* for_each
|
44
|
+
* from_pairs
|
39
45
|
* group_by
|
40
46
|
* gt
|
41
47
|
* gte
|
@@ -47,6 +53,7 @@
|
|
47
53
|
* insert
|
48
54
|
* intersection
|
49
55
|
* invoker
|
56
|
+
* is
|
50
57
|
* is_empty
|
51
58
|
* is_nil
|
52
59
|
* join
|
@@ -68,6 +75,7 @@
|
|
68
75
|
* n_ary
|
69
76
|
* not
|
70
77
|
* nth
|
78
|
+
* of
|
71
79
|
* omit
|
72
80
|
* once
|
73
81
|
* or
|
@@ -108,9 +116,11 @@
|
|
108
116
|
* union_with
|
109
117
|
* uniq
|
110
118
|
* uniq_with - first argument is a function with 1 arity which transforms each list element and applies uniq function to results
|
119
|
+
* unnest
|
111
120
|
* use_with
|
112
121
|
* values
|
113
122
|
* where
|
114
123
|
* xprod
|
115
124
|
* zip
|
125
|
+
* zip_obj
|
116
126
|
* zip_with
|
data/lib/ramda.rb
CHANGED
@@ -17,18 +17,21 @@ module Ramda
|
|
17
17
|
|
18
18
|
def_delegators Ramda::Function,
|
19
19
|
:always,
|
20
|
+
:ap,
|
20
21
|
:binary,
|
21
22
|
:comparator,
|
22
23
|
:compose,
|
23
24
|
:construct,
|
24
25
|
:converge,
|
25
26
|
:curry,
|
27
|
+
:empty,
|
26
28
|
:flip,
|
27
29
|
:identity,
|
28
30
|
:invoker,
|
29
31
|
:juxt,
|
30
32
|
:memoize,
|
31
33
|
:n_ary,
|
34
|
+
:of,
|
32
35
|
:once,
|
33
36
|
:pipe,
|
34
37
|
:tap,
|
@@ -39,10 +42,12 @@ module Ramda
|
|
39
42
|
:all,
|
40
43
|
:any,
|
41
44
|
:append,
|
45
|
+
:chain,
|
42
46
|
:concat,
|
43
47
|
:contains,
|
44
48
|
:drop,
|
45
49
|
:filter,
|
50
|
+
:from_pairs,
|
46
51
|
:find,
|
47
52
|
:find_index,
|
48
53
|
:find_last,
|
@@ -77,15 +82,17 @@ module Ramda
|
|
77
82
|
:times,
|
78
83
|
:uniq,
|
79
84
|
:uniq_with,
|
85
|
+
:unnest,
|
80
86
|
:xprod,
|
81
87
|
:zip,
|
88
|
+
:zip_obj,
|
82
89
|
:zip_with
|
83
90
|
|
84
91
|
def_delegators Ramda::Logic,
|
85
92
|
:all_pass,
|
86
93
|
:and,
|
87
94
|
:any_pass,
|
88
|
-
|
95
|
+
:complement,
|
89
96
|
:if_else,
|
90
97
|
:is_empty,
|
91
98
|
:not,
|
@@ -96,6 +103,7 @@ module Ramda
|
|
96
103
|
:dec,
|
97
104
|
:divide,
|
98
105
|
:inc,
|
106
|
+
# :math_mod,
|
99
107
|
:modulo,
|
100
108
|
:multiply,
|
101
109
|
:product,
|
@@ -146,5 +154,6 @@ module Ramda
|
|
146
154
|
:to_upper
|
147
155
|
|
148
156
|
def_delegators Ramda::Type,
|
157
|
+
:is,
|
149
158
|
:is_nil
|
150
159
|
end
|
data/lib/ramda/function.rb
CHANGED
@@ -6,10 +6,33 @@ module Ramda
|
|
6
6
|
module Function
|
7
7
|
extend ::Ramda::Internal::CurriedMethod
|
8
8
|
|
9
|
+
# Returns a function that always returns the given value. Note that
|
10
|
+
# for non-primitives the value returned is a reference to the original
|
11
|
+
# value.
|
12
|
+
# This function is known as const, constant, or K (for K combinator)
|
13
|
+
# in other languages and libraries.
|
14
|
+
#
|
15
|
+
# a -> (* -> a)
|
16
|
+
#
|
9
17
|
curried_method(:always) do |value|
|
10
18
|
-> { value }
|
11
19
|
end
|
12
20
|
|
21
|
+
# ap applies a list of functions to a list of values.
|
22
|
+
# Dispatches to the ap method of the second argument, if present.
|
23
|
+
# Also treats curried functions as applicatives.
|
24
|
+
#
|
25
|
+
# [a -> b] -> [a] -> [b]
|
26
|
+
# Apply f => f (a -> b) -> f a -> f b
|
27
|
+
#
|
28
|
+
curried_method(:ap) do |fns, xs|
|
29
|
+
if xs.respond_to?(:ap)
|
30
|
+
xs.ap(fns)
|
31
|
+
else
|
32
|
+
fns.flat_map { |fn| xs.map(&fn) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
13
36
|
# Wraps a function of any arity (including nullary) in a function that
|
14
37
|
# accepts exactly 2 parameters. Any extraneous parameters will not be
|
15
38
|
# passed to the supplied function.
|
@@ -81,6 +104,24 @@ module Ramda
|
|
81
104
|
fn.to_proc.curry
|
82
105
|
end
|
83
106
|
|
107
|
+
# Returns the empty value of its argument's type. Ramda defines the empty
|
108
|
+
# value of Array ([]), Object ({}), String ('), and Arguments.
|
109
|
+
# Other types are supported if they define <Type>.empty.
|
110
|
+
#
|
111
|
+
# Dispatches to the empty method of the first argument, if present.'))
|
112
|
+
#
|
113
|
+
# a -> a
|
114
|
+
#
|
115
|
+
curried_method(:empty) do |x|
|
116
|
+
if x.respond_to?(:empty)
|
117
|
+
x.empty
|
118
|
+
elsif x.class.respond_to?(:empty)
|
119
|
+
x.class.empty
|
120
|
+
else
|
121
|
+
x.class.new
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
84
125
|
# Returns a new function much like the supplied one, except that the
|
85
126
|
# first two arguments' order is reversed.
|
86
127
|
#
|
@@ -137,12 +178,26 @@ module Ramda
|
|
137
178
|
end.curry
|
138
179
|
end
|
139
180
|
|
181
|
+
# Wraps a function of any arity (including nullary) in a function that
|
182
|
+
# accepts exactly n parameters. Any extraneous parameters will not be
|
183
|
+
# passed to the supplied function.
|
184
|
+
#
|
185
|
+
# Number -> (* -> a) -> (* -> a)
|
186
|
+
#
|
140
187
|
curried_method(:n_ary) do |arity, fn|
|
141
188
|
Ramda::Internal::FunctionWithArity.new.call(arity) do |*args|
|
142
189
|
fn.call(*(args.first(arity) + Array.new(fn.arity - arity, nil)))
|
143
190
|
end.curry
|
144
191
|
end
|
145
192
|
|
193
|
+
# Returns a singleton array containing the value provided.
|
194
|
+
#
|
195
|
+
# a -> [a]
|
196
|
+
#
|
197
|
+
curried_method(:of) do |x|
|
198
|
+
[x]
|
199
|
+
end
|
200
|
+
|
146
201
|
# Accepts a function fn and returns a function that guards invocation of fn
|
147
202
|
# such that fn can only ever be called once, no matter how many times the
|
148
203
|
# returned function is invoked. The first value calculated is returned
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'function_with_arity'
|
2
|
+
|
1
3
|
module Ramda
|
2
4
|
module Internal
|
3
5
|
# Curried Method
|
@@ -5,6 +7,7 @@ module Ramda
|
|
5
7
|
def curried_method(name, &block)
|
6
8
|
define_singleton_method(name) do |*args|
|
7
9
|
curried = block.curry
|
10
|
+
# curried.define_singleton_method(:origin_arity) { block.arity }
|
8
11
|
|
9
12
|
return curried if args.empty?
|
10
13
|
|
@@ -7,19 +7,19 @@ module Ramda
|
|
7
7
|
# rubocop:disable Metrics/ParameterLists
|
8
8
|
def call(arity)
|
9
9
|
case arity
|
10
|
-
when 0
|
10
|
+
when 0, -1
|
11
11
|
->(*a) { yield(*a) }
|
12
|
-
when 1
|
12
|
+
when 1, -2
|
13
13
|
->(a, *b) { yield(a, *b) }
|
14
|
-
when 2
|
14
|
+
when 2, -3
|
15
15
|
->(a, b, *c) { yield(a, b, *c) }
|
16
|
-
when 3
|
16
|
+
when 3, -4
|
17
17
|
->(a, b, c, *d) { yield(a, b, c, *d) }
|
18
|
-
when 4
|
18
|
+
when 4, -5
|
19
19
|
->(a, b, c, d, *e) { yield(a, b, c, d, *e) }
|
20
|
-
when 5
|
20
|
+
when 5, -6
|
21
21
|
->(a, b, c, d, e, *f) { yield(a, b, c, d, e, *f) }
|
22
|
-
when 6
|
22
|
+
when 6, -7
|
23
23
|
->(a, b, c, d, e, f, *g) { yield(a, b, c, d, e, f, *g) }
|
24
24
|
else
|
25
25
|
raise ArgumentError, "Arrity #{arity} is not supported"
|
data/lib/ramda/list.rb
CHANGED
@@ -37,6 +37,24 @@ module Ramda
|
|
37
37
|
xs.dup + [x]
|
38
38
|
end
|
39
39
|
|
40
|
+
# chain maps a function over a list and concatenates the results. chain is
|
41
|
+
# also known as flatMap in some libraries
|
42
|
+
#
|
43
|
+
# Dispatches to the chain or bind method of the second argument, if present,
|
44
|
+
# according to the FantasyLand Chain spec.
|
45
|
+
#
|
46
|
+
# Chain m => (a -> m b) -> m a -> m b
|
47
|
+
#
|
48
|
+
curried_method(:chain) do |fn, xs|
|
49
|
+
if xs.respond_to?(:chain)
|
50
|
+
xs.chain(fn)
|
51
|
+
elsif xs.respond_to?(:bind)
|
52
|
+
xs.bind(fn)
|
53
|
+
else
|
54
|
+
xs.flat_map(&fn)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
40
58
|
# Returns the result of concatenating the given lists or strings.
|
41
59
|
# String -> String -> String
|
42
60
|
#
|
@@ -96,6 +114,15 @@ module Ramda
|
|
96
114
|
end
|
97
115
|
end
|
98
116
|
|
117
|
+
# Creates a new object from a list key-value pairs. If a key appears in
|
118
|
+
# multiple pairs, the rightmost pair is included in the object.
|
119
|
+
#
|
120
|
+
# [[k,v]] -> {k: v}
|
121
|
+
#
|
122
|
+
curried_method(:from_pairs) do |xs|
|
123
|
+
Hash[xs]
|
124
|
+
end
|
125
|
+
|
99
126
|
# Returns the first element of the list which matches the predicate,
|
100
127
|
# or undefined if no element matches.
|
101
128
|
#
|
@@ -440,6 +467,14 @@ module Ramda
|
|
440
467
|
xs.uniq(&fn)
|
441
468
|
end
|
442
469
|
|
470
|
+
# Shorthand for R.chain(R.identity), which removes one level of nesting from any Chain.
|
471
|
+
#
|
472
|
+
# Chain c => c (c a) -> c a
|
473
|
+
#
|
474
|
+
curried_method(:unnest) do |xs|
|
475
|
+
Ramda.chain(Ramda.identity, xs)
|
476
|
+
end
|
477
|
+
|
443
478
|
# Creates a new list out of the two supplied by creating each possible pair
|
444
479
|
# from the lists.
|
445
480
|
#
|
@@ -460,6 +495,16 @@ module Ramda
|
|
460
495
|
xs1.zip(xs2)
|
461
496
|
end
|
462
497
|
|
498
|
+
# Creates a new object out of a list of keys and a list of values. Key/value
|
499
|
+
# pairing is truncated to the length of the shorter of the two lists. Note:
|
500
|
+
# zipObj is equivalent to pipe(zip_with(pair), from_pairs).
|
501
|
+
#
|
502
|
+
# [String] -> [*] -> {String: *}
|
503
|
+
#
|
504
|
+
curried_method(:zip_obj) do |xs1, xs2|
|
505
|
+
Hash[xs1.zip(xs2)]
|
506
|
+
end
|
507
|
+
|
463
508
|
# Creates a new list out of the two supplied by applying the function to each
|
464
509
|
# equally-positioned pair in the lists. The returned list is truncated to the
|
465
510
|
# length of the shorter of the two input lists.
|
data/lib/ramda/math.rb
CHANGED
@@ -37,6 +37,12 @@ module Ramda
|
|
37
37
|
a + 1
|
38
38
|
end
|
39
39
|
|
40
|
+
curried_method(:math_mod) do |x, y|
|
41
|
+
# if (!_isInteger(m)) { return NaN; }
|
42
|
+
# if (!_isInteger(p) || p < 1) { return NaN; }
|
43
|
+
# return ((m % p) + p) % p;
|
44
|
+
end
|
45
|
+
|
40
46
|
# Divides the first parameter by the second and returns the remainder.
|
41
47
|
#
|
42
48
|
# Number -> Number -> Number
|
data/lib/ramda/type.rb
CHANGED
@@ -5,7 +5,19 @@ module Ramda
|
|
5
5
|
module Type
|
6
6
|
extend ::Ramda::Internal::CurriedMethod
|
7
7
|
|
8
|
+
# See if an object (val) is an instance of the supplied constructor.
|
9
|
+
# This function will check up the inheritance chain, if any.
|
10
|
+
#
|
11
|
+
# (* -> {*}) -> a -> Boolean
|
12
|
+
#
|
13
|
+
curried_method(:is) do |type, x|
|
14
|
+
x.is_a?(type)
|
15
|
+
end
|
16
|
+
|
8
17
|
# Checks if the input value is nil.
|
18
|
+
#
|
19
|
+
# * -> Boolean
|
20
|
+
#
|
9
21
|
curried_method(:is_nil, &:nil?)
|
10
22
|
end
|
11
23
|
end
|
data/lib/ramda/version.rb
CHANGED
data/spec/ramda/function_spec.rb
CHANGED
@@ -15,6 +15,14 @@ describe Ramda::Function do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
context '#ap' do
|
19
|
+
it 'from docs' do
|
20
|
+
expect(r.ap([R.multiply(2), R.add(3)], [1, 2, 3])).to eq([2, 4, 6, 4, 5, 6])
|
21
|
+
expect(r.ap([R.concat('tasty '), R.to_upper], ['pizza', 'salad']))
|
22
|
+
.to eq(['tasty pizza', 'tasty salad', 'PIZZA', 'SALAD'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
context '#binary' do
|
19
27
|
it 'from docs' do
|
20
28
|
takes_three_args = ->(a, b, c) { [a, b, c]; }
|
@@ -83,6 +91,24 @@ describe Ramda::Function do
|
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
94
|
+
context '#empty' do
|
95
|
+
it 'from docs' do
|
96
|
+
expect(r.empty([1, 2, 3])).to eq([])
|
97
|
+
expect(r.empty('unicorns')).to eq('')
|
98
|
+
expect(r.empty(x: 1, y: 2)).to eq({})
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'object has empty method' do
|
102
|
+
obj = Class.new do
|
103
|
+
def empty
|
104
|
+
[]
|
105
|
+
end
|
106
|
+
end.new
|
107
|
+
|
108
|
+
expect(r.empty(obj)).to eq([])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
86
112
|
context '#flip' do
|
87
113
|
def merge_tree
|
88
114
|
->(a, b, c) { [a, b, c] }
|
@@ -174,6 +200,13 @@ describe Ramda::Function do
|
|
174
200
|
end
|
175
201
|
end
|
176
202
|
|
203
|
+
context '#of' do
|
204
|
+
it 'from docs' do
|
205
|
+
expect(r.of(nil)).to eq([nil])
|
206
|
+
expect(r.of([42])).to eq([[42]])
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
177
210
|
context '#once' do
|
178
211
|
it 'from docs' do
|
179
212
|
add_one_once = r.once(->(x) { x + 1 })
|
@@ -8,6 +8,7 @@ describe Ramda::Internal::CurriedMethod do
|
|
8
8
|
a + b + c
|
9
9
|
end
|
10
10
|
|
11
|
+
# expect(instance.sample_method.origin_arity).to be(3)
|
11
12
|
expect(instance.sample_method.call(1).call(2).call(3)).to be(6)
|
12
13
|
expect(instance.sample_method(1).call(2).call(3)).to be(6)
|
13
14
|
expect(instance.sample_method(1, 2).call(3)).to be(6)
|
data/spec/ramda/list_spec.rb
CHANGED
@@ -44,6 +44,42 @@ describe Ramda::List do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
context '#chain' do
|
48
|
+
it 'from docs' do
|
49
|
+
duplicate = ->(n) { [n, n] }
|
50
|
+
expect(r.chain(duplicate, [1, 2, 3])).to eq([1, 1, 2, 2, 3, 3])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'monad with chain' do
|
54
|
+
monad = Class.new do
|
55
|
+
def chain(fn)
|
56
|
+
fn.call(10)
|
57
|
+
end
|
58
|
+
end.new
|
59
|
+
|
60
|
+
expect(r.chain(Ramda.add(5), monad)).to eq(15)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'monad with bind' do
|
64
|
+
monad = Class.new do
|
65
|
+
def bind(fn)
|
66
|
+
fn.call(10)
|
67
|
+
end
|
68
|
+
end.new
|
69
|
+
|
70
|
+
expect(r.chain(Ramda.add(5), monad)).to eq(15)
|
71
|
+
end
|
72
|
+
|
73
|
+
# it 'multiple args' do
|
74
|
+
# expect(r.chain(R.compose(R.append, R.head)).call([1, 2, 3])).to eq([1, 2, 3, 1])
|
75
|
+
# end
|
76
|
+
|
77
|
+
it 'maps a function (a -> [b]) into a (shallow) flat result' do
|
78
|
+
times2 = ->(x) { [x * 2] }
|
79
|
+
expect(R.chain(times2).call([1, 2, 3, 4])).to eq([2, 4, 6, 8])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
47
83
|
context '#concat' do
|
48
84
|
it 'from docs' do
|
49
85
|
expect(r.concat('ABC', 'DEF')).to eq('ABCDEF')
|
@@ -98,6 +134,12 @@ describe Ramda::List do
|
|
98
134
|
end
|
99
135
|
end
|
100
136
|
|
137
|
+
context '#from_pairs' do
|
138
|
+
it 'from docs' do
|
139
|
+
expect(r.from_pairs([[:a, 1], [:b, 2], [:c, 3]])).to eq(a: 1, b: 2, c: 3)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
101
143
|
context '#find' do
|
102
144
|
it 'from docs' do
|
103
145
|
list = [{ a: 1 }, { a: 2 }, { a: 3 }]
|
@@ -477,6 +519,13 @@ describe Ramda::List do
|
|
477
519
|
end
|
478
520
|
end
|
479
521
|
|
522
|
+
context '#unnest' do
|
523
|
+
it 'from docs' do
|
524
|
+
expect(r.unnest([1, [2], [[3]]])).to eq([1, 2, [3]])
|
525
|
+
expect(r.unnest([[1, 2], [3, 4], [5, 6]])).to eq([1, 2, 3, 4, 5, 6])
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
480
529
|
context '#xprod' do
|
481
530
|
it 'from docs' do
|
482
531
|
expect(r.xprod([1, 2], ['a', 'b']))
|
@@ -491,6 +540,12 @@ describe Ramda::List do
|
|
491
540
|
end
|
492
541
|
end
|
493
542
|
|
543
|
+
context '#zip_obj' do
|
544
|
+
it 'from docs' do
|
545
|
+
expect(r.zip_obj([:a, :b, :c], [1, 2, 3])).to eq(a: 1, b: 2, c: 3)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
494
549
|
context '#zip_with' do
|
495
550
|
it 'from docs' do
|
496
551
|
f = ->(x, y) { Ramda.join('', [x, y]) }
|
data/spec/ramda/logic_spec.rb
CHANGED
@@ -30,13 +30,13 @@ describe Ramda::Logic do
|
|
30
30
|
expect(is_black_card.call(rank: 'Q', suit: 'diamond')).to be_falsey
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
context '#complement' do
|
34
34
|
it 'from docs' do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
is_not_nil = r.complement(R.is_nil)
|
36
|
+
expect(R.is_nil(nil)).to be_truthy
|
37
|
+
expect(is_not_nil.call(nil)).to be_falsey
|
38
|
+
expect(R.is_nil(7)).to be_falsey
|
39
|
+
expect(is_not_nil.call(7)).to be_truthy
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/spec/ramda/math_spec.rb
CHANGED
@@ -35,6 +35,22 @@ describe Ramda::Math do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
xcontext '#math_mod' do
|
39
|
+
it 'from docs' do
|
40
|
+
expect(R.math_mod(-17, 5)).to eq(3)
|
41
|
+
expect(R.math_mod(17, 5)).to eq(2)
|
42
|
+
expect(R.math_mod(17, -5)).to be(nil)
|
43
|
+
expect(R.math_mod(17, 0)).to be(nil)
|
44
|
+
expect(R.math_mod(17.2, 5)).to be(nil)
|
45
|
+
expect(R.math_mod(17, 5.3)).to be(nil)
|
46
|
+
|
47
|
+
seventeen_mod = R.mathMod(17)
|
48
|
+
expect(seventeen_mod.call(3)).to eq(2)
|
49
|
+
expect(seventeen_mod.call(4)).to eq(1)
|
50
|
+
expect(seventeen_mod.call(10)).to eq(7)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
38
54
|
context '#modulo' do
|
39
55
|
it 'from docs' do
|
40
56
|
expect(r.modulo(0, 3)).to be(0)
|
data/spec/ramda/object_spec.rb
CHANGED
@@ -158,13 +158,13 @@ describe Ramda::Object do
|
|
158
158
|
context '#where' do
|
159
159
|
it 'from docs' do
|
160
160
|
pred = R.where(a: R.equals('foo'),
|
161
|
-
|
161
|
+
b: R.complement(R.equals('bar')),
|
162
162
|
x: R.lt(10),
|
163
163
|
y: R.gt(20))
|
164
164
|
|
165
165
|
expect(pred.call(a: 'foo', b: 'xxx', x: 11, y: 19)).to be_truthy
|
166
166
|
expect(pred.call(a: 'xxx', b: 'xxx', x: 11, y: 19)).to be_falsey
|
167
|
-
|
167
|
+
expect(pred.call(a: 'foo', b: 'bar', x: 11, y: 19)).to be_falsey
|
168
168
|
expect(pred.call(a: 'foo', b: 'xxx', x: 10, y: 19)).to be_falsey
|
169
169
|
expect(pred.call(a: 'foo', b: 'xxx', x: 11, y: 20)).to be_falsey
|
170
170
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ramda::Type do
|
4
|
+
let(:r) { described_class }
|
5
|
+
|
6
|
+
context '#is' do
|
7
|
+
it 'from docs' do
|
8
|
+
expect(r.is(Hash, {})).to be_truthy
|
9
|
+
expect(r.is(Integer, 1)).to be_truthy
|
10
|
+
expect(r.is(Hash, 1)).to be_falsey
|
11
|
+
expect(r.is(String, 's')).to be_truthy
|
12
|
+
expect(r.is(String, '')).to be_truthy
|
13
|
+
expect(r.is(Hash, 's')).to be_falsey
|
14
|
+
expect(r.is(Integer, {})).to be_falsey
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#is_nil' do
|
19
|
+
it 'from docs' do
|
20
|
+
expect(r.is_nil(nil)).to be_truthy
|
21
|
+
expect(r.is_nil(0)).to be_falsey
|
22
|
+
expect(r.is_nil([])).to be_falsey
|
23
|
+
expect(r.is_nil('')).to be_falsey
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/ramda_spec.rb
CHANGED
@@ -7,6 +7,9 @@ describe Ramda do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
# r(:keys_in)
|
11
|
+
# r(:math_mod)
|
12
|
+
# r(:values_in)
|
10
13
|
r(:add)
|
11
14
|
r(:all)
|
12
15
|
r(:all_pass)
|
@@ -14,11 +17,14 @@ describe Ramda do
|
|
14
17
|
r(:and)
|
15
18
|
r(:any)
|
16
19
|
r(:any_pass)
|
20
|
+
r(:ap)
|
17
21
|
r(:append)
|
18
22
|
r(:assoc)
|
23
|
+
r(:binary)
|
24
|
+
r(:chain)
|
19
25
|
r(:clone)
|
20
26
|
r(:comparator)
|
21
|
-
|
27
|
+
r(:complement)
|
22
28
|
r(:compose)
|
23
29
|
r(:concat)
|
24
30
|
r(:construct)
|
@@ -32,6 +38,7 @@ describe Ramda do
|
|
32
38
|
r(:dissoc)
|
33
39
|
r(:divide)
|
34
40
|
r(:drop)
|
41
|
+
r(:empty)
|
35
42
|
r(:eq_by)
|
36
43
|
r(:eq_props)
|
37
44
|
r(:equals)
|
@@ -43,6 +50,7 @@ describe Ramda do
|
|
43
50
|
r(:flatten)
|
44
51
|
r(:flip)
|
45
52
|
r(:for_each)
|
53
|
+
r(:from_pairs)
|
46
54
|
r(:group_by)
|
47
55
|
r(:gt)
|
48
56
|
r(:gte)
|
@@ -54,12 +62,12 @@ describe Ramda do
|
|
54
62
|
r(:insert)
|
55
63
|
r(:intersection)
|
56
64
|
r(:invoker)
|
65
|
+
r(:is)
|
57
66
|
r(:is_empty)
|
58
67
|
r(:is_nil)
|
59
68
|
r(:join)
|
60
69
|
r(:juxt)
|
61
70
|
r(:keys)
|
62
|
-
# r(:keys_in)
|
63
71
|
r(:last)
|
64
72
|
r(:last_index_of)
|
65
73
|
r(:length)
|
@@ -76,6 +84,7 @@ describe Ramda do
|
|
76
84
|
r(:n_ary)
|
77
85
|
r(:not)
|
78
86
|
r(:nth)
|
87
|
+
r(:of)
|
79
88
|
r(:omit)
|
80
89
|
r(:once)
|
81
90
|
r(:or)
|
@@ -116,11 +125,12 @@ describe Ramda do
|
|
116
125
|
r(:union_with)
|
117
126
|
r(:uniq)
|
118
127
|
r(:uniq_with)
|
128
|
+
r(:unnest)
|
119
129
|
r(:use_with)
|
120
130
|
r(:values)
|
121
|
-
# r(:values_in)
|
122
131
|
r(:where)
|
123
132
|
r(:xprod)
|
124
133
|
r(:zip)
|
134
|
+
r(:zip_obj)
|
125
135
|
r(:zip_with)
|
126
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramda-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Lazebny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby version of Ramda Js library.
|
14
14
|
email:
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- spec/ramda/object_spec.rb
|
48
48
|
- spec/ramda/relation_spec.rb
|
49
49
|
- spec/ramda/string_spec.rb
|
50
|
+
- spec/ramda/type_spec.rb
|
50
51
|
- spec/ramda_spec.rb
|
51
52
|
- spec/spec_helper.rb
|
52
53
|
homepage: https://github.com/lazebny/ramda-ruby
|
@@ -79,6 +80,7 @@ test_files:
|
|
79
80
|
- spec/ramda/logic_spec.rb
|
80
81
|
- spec/ramda/string_spec.rb
|
81
82
|
- spec/ramda/list_spec.rb
|
83
|
+
- spec/ramda/type_spec.rb
|
82
84
|
- spec/ramda/object_spec.rb
|
83
85
|
- spec/ramda/function_spec.rb
|
84
86
|
- spec/ramda/relation_spec.rb
|