ramda-ruby 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b926d96db763d6a43b3d6e114448169ebe87975
4
- data.tar.gz: aa89681ca4ab9dfb72413e9f21dacbf9ed42a294
3
+ metadata.gz: 3be47564e590c02c9edbfe24ce475676fc9e85b3
4
+ data.tar.gz: e27d96aa0d83e50b482cb2ada7d09c60dbbf2152
5
5
  SHA512:
6
- metadata.gz: 288ef7275478fdd4ed28044dbfafc65ab2e366d988c4e2ce212f99cb1881522c56a9d0a4f0cc233902683c66b211abd141ee8619bf8535441f3f5213eb9aa9f6
7
- data.tar.gz: b85a150288793a5fa4abe9e3112b2c5f2973614933af18fba0ec272db01ffd25d500f37f6c74665d3d6da3608b54c8aebd8ba743c44a26899fd2706aa96dd314
6
+ metadata.gz: 610df76cc6e853a7850ff2f7ef3a886b864ad93f807fbd032353d073c7eba6e361ad6f3790c6b234ac6797bf4f87aec643ab8a908ab6058d40f8529c1662d98a
7
+ data.tar.gz: 726d0b3245a24232e8949218e15ad50cff16356a35a675d1b89721f31d558d35bca5048da75840b182fa156f24aa4de40625c424d792fb23690d352c8752ba47
data/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
  Not Released
2
2
  ---------------
3
3
 
4
+ Release 0.6.0
5
+
6
+ Added:
7
+
8
+ * F
9
+ * T
10
+ * __ - first function call should have all arguments g(___2, __)(1, 3), this means that it doesn't support g(__, 2)(1)(3), g(__, 2)(1, 3) and g(__, 2)(__, 3)(1)
11
+ * bind
12
+ * cond
13
+ * prop_or
14
+ * replace - it uses a gsub method and global replacement
15
+ * trim
16
+
4
17
  Release 0.5.0
5
18
  ---------------
6
19
 
@@ -26,7 +39,8 @@ Added:
26
39
  * ap
27
40
  * chain
28
41
  * complement
29
- * empty - uses x.class.new for defining new empty object if empty method does not exist
42
+ * empty - uses x.class.new for defining new empty object if empty method
43
+ does not exist
30
44
  * from_pairs
31
45
  * is
32
46
  * of
@@ -56,7 +70,8 @@ Added:
56
70
  * binary
57
71
  * path
58
72
  * unary
59
- * uniq_with - first argument is a function with 1 arity which transforms each list element and applies uniq function to results
73
+ * uniq_with - first argument is a function with 1 arity which transforms
74
+ each list element and applies uniq function to results
60
75
  * (pending) keys_in
61
76
  * (pending) values_in
62
77
 
data/README.md CHANGED
@@ -49,7 +49,10 @@ Ruby scpecific examples can be found in [tests](spec/ramda).
49
49
 
50
50
  ## Usage
51
51
 
52
+ Pointless Style:
53
+
52
54
  ```ruby
55
+
53
56
  R = Ramda
54
57
 
55
58
  players = [
@@ -60,6 +63,16 @@ Ruby scpecific examples can be found in [tests](spec/ramda).
60
63
 
61
64
  best_player = R.pipe(R.sort_by(R.prop(:score)), R.reverse, R.head, R.prop(:name))
62
65
  best_player.call(players) # Ivan
66
+
67
+ ```
68
+
69
+ Placeholder:
70
+
71
+ ```ruby
72
+
73
+ reset_to_default = R.merge(R.__, x: 0)
74
+ reset_to_default.call(x: 5, y: 2) # { x: 0, y: 2 }
75
+
63
76
  ```
64
77
 
65
78
  ## Development
data/ROADMAP.md CHANGED
@@ -2,14 +2,6 @@
2
2
 
3
3
  * Find out suitable documentation format
4
4
 
5
- ### release 0.6.0
6
-
7
- * __
8
- * bind
9
- * cond
10
- * prop_or
11
- * trim
12
-
13
5
  ### release 0.7.0
14
6
 
15
7
  * apply
@@ -18,7 +10,6 @@
18
10
  * lift
19
11
  * lift_n
20
12
  * path_eq
21
- * replace
22
13
 
23
14
  ### release 0.8.0
24
15
 
@@ -40,7 +31,6 @@
40
31
  * dec
41
32
  * drop_while
42
33
  * evolve
43
- * F
44
34
  * inc
45
35
  * init
46
36
  * insert_all
@@ -50,6 +40,5 @@
50
40
  * map_obj_indexed
51
41
  * negate
52
42
  * nth_arg
53
- * T
54
43
  * to_lower
55
44
  * to_upper
data/docs/FUNCTIONS.md CHANGED
@@ -1,7 +1,10 @@
1
- * (pending) to_pairs_in
2
1
  * (pending) keys_in
3
2
  * (pending) math_mod
3
+ * (pending) to_pairs_in
4
4
  * (pending) values_in
5
+ * F
6
+ * T
7
+ * __ - first function call should have all arguments g(___2, __)(1, 3), this means that it doesn't support g(__, 2)(1)(3), g(__, 2)(1, 3) and g(__, 2)(__, 3)(1)
5
8
  * add
6
9
  * all
7
10
  * all_pass
@@ -13,12 +16,14 @@
13
16
  * append
14
17
  * assoc
15
18
  * binary
19
+ * bind
16
20
  * chain
17
21
  * clone
18
22
  * comparator
19
23
  * complement
20
24
  * compose
21
25
  * concat
26
+ * cond
22
27
  * construct
23
28
  * construct_n
24
29
  * contains
@@ -93,6 +98,7 @@
93
98
  * project
94
99
  * prop
95
100
  * prop_eq
101
+ * prop_or
96
102
  * props
97
103
  * range
98
104
  * reduce
@@ -100,6 +106,7 @@
100
106
  * reject
101
107
  * remove
102
108
  * repeat
109
+ * replace - it uses a gsub method and global replacement
103
110
  * reverse
104
111
  * slice
105
112
  * sort
@@ -115,6 +122,7 @@
115
122
  * to_lower
116
123
  * to_pairs
117
124
  * to_upper
125
+ * trim
118
126
  * unary
119
127
  * union
120
128
  * union_with
@@ -7,6 +7,38 @@ module Ramda
7
7
  module Function
8
8
  extend ::Ramda::Internal::CurriedMethod
9
9
 
10
+ # A special placeholder value used to specify "gaps" within curried
11
+ # functions, allowing partial application of any combination of
12
+ # arguments, regardless of their positions.
13
+ #
14
+ # If g is a curried ternary function and _ is R.__, the following are equivalent:
15
+ #
16
+ # g(1, 2, 3)
17
+ # g(_, 2, 3)(1)
18
+ # g(_, _, 3)(1)(2)
19
+ # g(_, _, 3)(1, 2)
20
+ # g(_, 2, _)(1, 3)
21
+ # g(_, 2)(1)(3)
22
+ # g(_, 2)(1, 3)
23
+ # g(_, 2)(_, 3)(1)
24
+ #
25
+
26
+ # rubocop:disable Style/MethodName
27
+ def self.F
28
+ ->(*) { false }
29
+ end
30
+ # rubocop:enable Style/MethodName
31
+
32
+ # rubocop:disable Style/MethodName
33
+ def self.T
34
+ ->(*) { true }
35
+ end
36
+ # rubocop:enable Style/MethodName
37
+
38
+ def self.__
39
+ :ramda_placeholder
40
+ end
41
+
10
42
  # Returns a function that always returns the given value. Note that
11
43
  # for non-primitives the value returned is a reference to the original
12
44
  # value.
@@ -16,7 +48,7 @@ module Ramda
16
48
  # a -> (* -> a)
17
49
  #
18
50
  curried_method(:always) do |value|
19
- -> { value }
51
+ ->(*) { value }
20
52
  end
21
53
 
22
54
  # ap applies a list of functions to a list of values.
@@ -43,6 +75,14 @@ module Ramda
43
75
  n_ary(2, fn)
44
76
  end
45
77
 
78
+ # Creates a function that is bound to a context.
79
+ #
80
+ # (* -> *) -> {*} -> (* -> *)
81
+ #
82
+ curried_method(:bind) do |fn, ctx|
83
+ fn.unbind.bind(ctx)
84
+ end
85
+
46
86
  # Makes a comparator function out of a function that reports whether
47
87
  # the first element is less than the second.
48
88
  #
@@ -116,7 +156,7 @@ module Ramda
116
156
  # (* -> a) -> (* -> a)
117
157
  #
118
158
  curried_method(:curry) do |fn|
119
- fn.to_proc.curry
159
+ curried_method_body(fn.arity, &fn)
120
160
  end
121
161
 
122
162
  # Returns a curried equivalent of the provided function, with the
@@ -145,7 +185,7 @@ module Ramda
145
185
  # Number -> (* -> a) -> (* -> a)
146
186
  #
147
187
  curried_method(:curry_n) do |arity, fn|
148
- Ramda::Internal::FunctionWithArity.new.call(arity, &fn).curry
188
+ curried_method_body(arity, &fn)
149
189
  end
150
190
 
151
191
  # Returns the empty value of its argument's type. Ramda defines the empty
@@ -5,6 +5,40 @@ module Ramda
5
5
  # Curried Method
6
6
  module CurriedMethod
7
7
  def curried_method(name, &block)
8
+ define_singleton_method(name, &curried_method_body(block.arity, &block))
9
+ end
10
+
11
+ def curried_method_body(arity, &block)
12
+ Ramda::Internal::FunctionWithArity.new.call(arity) do |*args|
13
+ if args.include?(Ramda.__)
14
+ replace_placeholder(args, &block).curry
15
+ else
16
+ args.empty? ? block : yield(*args)
17
+ end
18
+ end.curry
19
+ end
20
+
21
+ def replace_placeholder(basic_args)
22
+ Ramda::Internal::FunctionWithArity.new.call(basic_args.count(Ramda.__)) do |*new_args|
23
+ cloned_args = basic_args.dup
24
+ new_args.each { |arg| cloned_args[cloned_args.index(Ramda.__)] = arg }
25
+ yield(*cloned_args)
26
+ end
27
+ end
28
+
29
+ def curried_method_v2(name, &block)
30
+ fn = Ramda::Internal::FunctionWithArity.new.call(block.arity) do |*args|
31
+ if args.empty?
32
+ block
33
+ else
34
+ yield(*args)
35
+ end
36
+ end
37
+
38
+ define_singleton_method(name, &fn.curry)
39
+ end
40
+
41
+ def curried_method_v1(name, &block)
8
42
  define_singleton_method(name) do |*args|
9
43
  curried = block.curry
10
44
  # curried.define_singleton_method(:origin_arity) { block.arity }
@@ -14,6 +48,34 @@ module Ramda
14
48
  curried.call(*args)
15
49
  end
16
50
  end
51
+
52
+ if RUBY_PLATFORM == 'java'
53
+ # This hack resolved issue:
54
+ # undefined method `__make_curry_proc__' for Ramda::Math:Module
55
+ #
56
+ # Source:
57
+ # https://github.com/jruby/jruby/issues/1523
58
+ #
59
+ # rubocop:disable Metrics/MethodLength
60
+ def __make_curry_proc__(proc, passed, arity)
61
+ is_lambda = proc.lambda?
62
+ passed.freeze
63
+
64
+ __send__((is_lambda ? :lambda : :proc)) do |*argv, &passed_proc|
65
+ my_passed = passed + argv
66
+ # original
67
+ # if my_passed.length < arity
68
+ # changed
69
+ if my_passed.length < arity.abs - 1
70
+ warn "#{caller[0]}: given block not used" unless passed_proc.nil?
71
+ __make_curry_proc__(proc, my_passed, arity)
72
+ else
73
+ proc.call(*my_passed)
74
+ end
75
+ end
76
+ end
77
+ # rubocop:enable Metrics/MethodLength
78
+ end
17
79
  end
18
80
  end
19
81
  end
data/lib/ramda/logic.rb CHANGED
@@ -31,6 +31,22 @@ module Ramda
31
31
  end.curry
32
32
  end
33
33
 
34
+ # Returns a function, fn, which encapsulates if/else, if/else, ...
35
+ # logic. R.cond takes a list of [predicate, transformer] pairs.
36
+ # All of the arguments to fn are applied to each of the predicates
37
+ # in turn until one returns a "truthy" value, at which point fn
38
+ # returns the result of applying its arguments to the corresponding
39
+ # transformer. If none of the predicates matches, fn returns nil.
40
+ #
41
+ # [[(*... -> Boolean),(*... -> *)]] -> (*... -> *)
42
+ #
43
+ curried_method(:cond) do |xs, x, *other_x|
44
+ _, then_fn = xs.find do |(when_fn, _)|
45
+ when_fn.call(x, *other_x)
46
+ end
47
+ then_fn.call(x, *other_x) unless then_fn.nil?
48
+ end
49
+
34
50
  # Creates a function that will process either the onTrue or the onFalse
35
51
  # function depending upon the result of the condition predicate.
36
52
  #
data/lib/ramda/object.rb CHANGED
@@ -133,6 +133,21 @@ module Ramda
133
133
  obj[key]
134
134
  end
135
135
 
136
+ # If the given, non-null object has an own property with the specified
137
+ # name, returns the value of that property. Otherwise returns
138
+ # the provided default value.
139
+ #
140
+ # a -> String -> Object -> a
141
+ #
142
+ curried_method(:prop_or) do |val, name, obj|
143
+ case obj
144
+ when Hash
145
+ obj[name] || val
146
+ else
147
+ obj.respond_to?(name) || val
148
+ end
149
+ end
150
+
136
151
  # Acts as multiple prop: array of keys in, array of values out.
137
152
  # Preserves order.
138
153
  #
data/lib/ramda/string.rb CHANGED
@@ -5,6 +5,30 @@ module Ramda
5
5
  module String
6
6
  extend ::Ramda::Internal::CurriedMethod
7
7
 
8
+ # Tests a regular expression against a String. Note that this function will
9
+ # return an empty array when there are no matches. This differs from
10
+ # String.prototype.match which returns null when there are no matches.
11
+ #
12
+ # RegExp -> String -> [String | NilClass]
13
+ #
14
+ curried_method(:match) do |exp, x|
15
+ case x
16
+ when ::String
17
+ x[exp]
18
+ # x.scan(exp).flatten
19
+ else
20
+ type_error(x)
21
+ end
22
+ end
23
+
24
+ # Replace a substring or regex match in a string with a replacement.
25
+ #
26
+ # RegExp|String -> String -> String -> Boolean -> String
27
+ #
28
+ curried_method(:replace) do |from, to, x|
29
+ x.gsub(from, to)
30
+ end
31
+
8
32
  # Splits a string into an array of strings based on the given separator.
9
33
  #
10
34
  # (String | RegExp) -> String -> [String]
@@ -25,21 +49,11 @@ module Ramda
25
49
  #
26
50
  curried_method(:to_lower, &:downcase)
27
51
 
28
- # Tests a regular expression against a String. Note that this function will
29
- # return an empty array when there are no matches. This differs from
30
- # String.prototype.match which returns null when there are no matches.
52
+ # Removes (strips) whitespace from both ends of the string.
31
53
  #
32
- # RegExp -> String -> [String | NilClass]
54
+ # String -> String
33
55
  #
34
- curried_method(:match) do |exp, x|
35
- case x
36
- when ::String
37
- x[exp]
38
- # x.scan(exp).flatten
39
- else
40
- type_error(x)
41
- end
42
- end
56
+ curried_method(:trim, &:strip)
43
57
 
44
58
  # TODO: Extract from this module
45
59
  def self.type_error(object)
data/lib/ramda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ramda
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
data/lib/ramda.rb CHANGED
@@ -16,9 +16,13 @@ module Ramda
16
16
  extend SingleForwardable
17
17
 
18
18
  def_delegators Ramda::Function,
19
+ :F,
20
+ :T,
21
+ :__,
19
22
  :always,
20
23
  :ap,
21
24
  :binary,
25
+ :bind,
22
26
  :comparator,
23
27
  :compose,
24
28
  :construct,
@@ -95,6 +99,7 @@ module Ramda
95
99
  :and,
96
100
  :any_pass,
97
101
  :complement,
102
+ :cond,
98
103
  :if_else,
99
104
  :is_empty,
100
105
  :not,
@@ -126,6 +131,7 @@ module Ramda
126
131
  :pick_all,
127
132
  :project,
128
133
  :prop,
134
+ :prop_or,
129
135
  :props,
130
136
  :to_pairs,
131
137
  # :to_pairs_in,
@@ -153,9 +159,11 @@ module Ramda
153
159
 
154
160
  def_delegators Ramda::String,
155
161
  :match,
162
+ :replace,
156
163
  :split,
157
164
  :to_lower,
158
- :to_upper
165
+ :to_upper,
166
+ :trim
159
167
 
160
168
  def_delegators Ramda::Type,
161
169
  :is,
@@ -3,6 +3,28 @@ require 'spec_helper'
3
3
  describe Ramda::Function do
4
4
  let(:r) { described_class }
5
5
 
6
+ context '#F' do
7
+ it 'from docs' do
8
+ expect(r.F.call).to be_falsey
9
+ end
10
+ end
11
+
12
+ context '#T' do
13
+ it 'from docs' do
14
+ expect(r.T.call).to be_truthy
15
+ end
16
+ end
17
+
18
+ context '#__' do
19
+ it 'from docs' do
20
+ greet = R.replace('{name}', r.__, 'Hello, {name}!')
21
+ expect(greet.call('Alice')).to eq('Hello, Alice!')
22
+
23
+ greet = R.replace(r.__, r.__, 'Hello, {name}!')
24
+ expect(greet.call('{name}', 'Alice')).to eq('Hello, Alice!')
25
+ end
26
+ end
27
+
6
28
  context '#always' do
7
29
  it 'from docs' do
8
30
  str = 'Tee'
@@ -33,6 +55,16 @@ describe Ramda::Function do
33
55
  end
34
56
  end
35
57
 
58
+ context '#bind' do
59
+ it 'from docs' do
60
+ fn = r.bind(''.method(:upcase), 'abcdef')
61
+ expect(fn.call).to eq('ABCDEF')
62
+
63
+ fn = r.bind(100.method(:+), 1000)
64
+ expect(fn.call(10)).to eq(1010)
65
+ end
66
+ end
67
+
36
68
  context '#comparator' do
37
69
  it 'from docs' do
38
70
  sort_rule = r.comparator(->(a, b) { a < b })
@@ -105,6 +137,16 @@ describe Ramda::Function do
105
137
  it 'can receive a method' do
106
138
  expect(r.curry(method(:test_method)).call(100)).to eq(100)
107
139
  end
140
+
141
+ it 'supports placeholder' do
142
+ g = r.curry(->(a, b, c) { a + b + c })
143
+
144
+ expect(g.call(1, 2, 3)).to eq(6)
145
+ expect(g.call(R.__, 2, 3).call(1)).to eq(6)
146
+ expect(g.call(R.__, R.__, 3).call(1).call(2)).to eq(6)
147
+ expect(g.call(R.__, R.__, 3).call(1, 2)).to eq(6)
148
+ expect(g.call(R.__, 2, R.__).call(1, 3)).to eq(6)
149
+ end
108
150
  end
109
151
 
110
152
  context '#curry_n' do
@@ -118,14 +160,14 @@ describe Ramda::Function do
118
160
  expect(g.call(4)).to eq(10)
119
161
  end
120
162
 
121
- xit 'with __' do
122
- # g(1, 2, 3)
123
- # g(_, 2, 3)(1)
124
- # g(_, _, 3)(1)(2)
125
- # g(_, _, 3)(1, 2)
126
- # g(_, 2)(1)(3)
127
- # g(_, 2)(1, 3)
128
- # g(_, 2)(_, 3)(1)
163
+ it 'supports placeholder' do
164
+ g = r.curry_n(3, ->(*args) { R.sum(args) })
165
+
166
+ expect(g.call(1, 2, 3)).to eq(6)
167
+ expect(g.call(R.__, 2, 3).call(1)).to eq(6)
168
+ expect(g.call(R.__, R.__, 3).call(1).call(2)).to eq(6)
169
+ expect(g.call(R.__, R.__, 3).call(1, 2)).to eq(6)
170
+ expect(g.call(R.__, 2, R.__).call(1, 3)).to eq(6)
129
171
  end
130
172
  end
131
173
 
@@ -3,15 +3,32 @@ require 'spec_helper'
3
3
  describe Ramda::Internal::CurriedMethod do
4
4
  let(:instance) { Class.new { extend Ramda::Internal::CurriedMethod } }
5
5
 
6
- it '#curried_method' do
7
- instance.curried_method(:sample_method) do |a, b, c|
8
- a + b + c
6
+ context '#curried_method' do
7
+ it 'without placeholder' do
8
+ instance.curried_method(:g) do |a, b, c|
9
+ a + b + c
10
+ end
11
+
12
+ # expect(instance.sample_method.origin_arity).to be(3)
13
+ expect(instance.g.call(1).call(2).call(3)).to be(6)
14
+ expect(instance.g(1).call(2).call(3)).to be(6)
15
+ expect(instance.g(1, 2).call(3)).to be(6)
16
+ expect(instance.g(1, 2, 3)).to be(6)
9
17
  end
10
18
 
11
- # expect(instance.sample_method.origin_arity).to be(3)
12
- expect(instance.sample_method.call(1).call(2).call(3)).to be(6)
13
- expect(instance.sample_method(1).call(2).call(3)).to be(6)
14
- expect(instance.sample_method(1, 2).call(3)).to be(6)
15
- expect(instance.sample_method(1, 2, 3)).to be(6)
19
+ it 'with placeholder' do
20
+ instance.curried_method(:g) do |a, b, c|
21
+ a + b + c
22
+ end
23
+
24
+ expect(instance.g(1, 2, 3)).to eq(6)
25
+ expect(instance.g(R.__, 2, 3).call(1)).to eq(6)
26
+ expect(instance.g(R.__, R.__, 3).call(1).call(2)).to eq(6)
27
+ expect(instance.g(R.__, R.__, 3).call(1, 2)).to eq(6)
28
+ expect(instance.g(R.__, 2, R.__).call(1, 3)).to eq(6)
29
+ # expect(instance.g(R.__, 2).call(1).call(3)).to eq(6)
30
+ # expect(instance.g(R.__, 2).call(1, 3)).to eq(6)
31
+ # expect(instance.g(R.__, 2).call(R.__, 3).call(1)).to eq(6)
32
+ end
16
33
  end
17
34
  end
@@ -57,7 +57,7 @@ describe Ramda::List do
57
57
  end
58
58
  end.new
59
59
 
60
- expect(r.chain(Ramda.add(5), monad)).to eq(15)
60
+ expect(r.chain(R.add(5), monad)).to eq(15)
61
61
  end
62
62
 
63
63
  it 'monad with bind' do
@@ -67,7 +67,7 @@ describe Ramda::List do
67
67
  end
68
68
  end.new
69
69
 
70
- expect(r.chain(Ramda.add(5), monad)).to eq(15)
70
+ expect(r.chain(R.add(5), monad)).to eq(15)
71
71
  end
72
72
 
73
73
  # it 'multiple args' do
@@ -548,7 +548,7 @@ describe Ramda::List do
548
548
 
549
549
  context '#zip_with' do
550
550
  it 'from docs' do
551
- f = ->(x, y) { Ramda.join('', [x, y]) }
551
+ f = ->(x, y) { R.join('', [x, y]) }
552
552
 
553
553
  expect(r.zip_with(f, [1, 2, 3], ['a', 'b', 'c'])).to eq(['1a', '2b', '3c'])
554
554
  end
@@ -40,12 +40,25 @@ describe Ramda::Logic do
40
40
  end
41
41
  end
42
42
 
43
+ context '#cond' do
44
+ it 'from docs' do
45
+ fn = R.cond([
46
+ [R.equals(0), R.always('water freezes at 0 C')],
47
+ [R.equals(100), R.always('water boils at 100 C')],
48
+ [R.T, ->(temp) { "nothing special happens at #{temp} C" }]
49
+ ])
50
+ expect(fn.call(0)).to eq('water freezes at 0 C')
51
+ expect(fn.call(50)).to eq('nothing special happens at 50 C')
52
+ expect(fn.call(100)).to eq('water boils at 100 C')
53
+ end
54
+ end
55
+
43
56
  context '#if_else' do
44
57
  it 'from docs' do
45
58
  inc_count = R.if_else(
46
- Ramda.prop(:count),
47
- Ramda.prop(:count),
48
- Ramda.identity
59
+ R.prop(:count),
60
+ R.prop(:count),
61
+ R.identity
49
62
  )
50
63
  expect(inc_count.call({})).to eq({})
51
64
  expect(inc_count.call(count: 1)).to eq(1)
@@ -24,6 +24,11 @@ describe Ramda::Math do
24
24
  expect(r.divide(71, 100)).to eq(0.71)
25
25
  end
26
26
 
27
+ it 'supports placeholder' do
28
+ half = r.divide(Ramda.__, 2)
29
+ expect(half.call(10)).to eq(5)
30
+ end
31
+
27
32
  it 'is curried' do
28
33
  expect(r.divide(1).call(4)).to eq(0.25)
29
34
  end
@@ -58,6 +63,12 @@ describe Ramda::Math do
58
63
  expect(r.modulo(21, 2)).to be(1)
59
64
  expect(r.modulo(17, 3)).to be(2)
60
65
  end
66
+
67
+ it 'supports placeholer' do
68
+ is_odd = R.modulo(R.__, 2)
69
+ expect(is_odd.call(42)).to eq(0)
70
+ expect(is_odd.call(21)).to eq(1)
71
+ end
61
72
  end
62
73
 
63
74
  context '#multipy' do
@@ -90,6 +101,12 @@ describe Ramda::Math do
90
101
  expect(complementary_angel.call(30)).to be(60)
91
102
  expect(complementary_angel.call(72)).to be(18)
92
103
  end
104
+
105
+ it 'support placeholder' do
106
+ minus5 = r.subtract(R.__, 5)
107
+ expect(minus5.call(17)).to eq(12)
108
+ expect(minus5.call(10)).to eq(5)
109
+ end
93
110
  end
94
111
 
95
112
  context '#sum' do
@@ -69,8 +69,11 @@ describe Ramda::Object do
69
69
 
70
70
  it 'is curried' do
71
71
  expect(r.merge(a: 1).call(b: 2)).to eq(a: 1, b: 2)
72
- # var resetToDefault = R.merge(R.__, {x: 0});
73
- # resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2}
72
+ end
73
+
74
+ it 'supports placeholder' do
75
+ reset_to_default = R.merge(R.__, x: 0)
76
+ expect(reset_to_default.call(x: 5, y: 2)).to eq(x: 0, y: 2)
74
77
  end
75
78
  end
76
79
 
@@ -119,6 +122,20 @@ describe Ramda::Object do
119
122
  end
120
123
  end
121
124
 
125
+ context '#prop_or' do
126
+ it 'from docs' do
127
+ alice = {
128
+ name: 'ALICE',
129
+ age: 101
130
+ }
131
+ favorite = R.prop('favoriteLibrary')
132
+ favorite_with_default = r.prop_or('Ramda', 'favoriteLibrary')
133
+
134
+ expect(favorite.call(alice)).to eq(nil)
135
+ expect(favorite_with_default.call(alice)).to eq('Ramda')
136
+ end
137
+ end
138
+
122
139
  context '#props' do
123
140
  it 'from docs' do
124
141
  expect(r.props([:x, :y], x: 1, y: 2)).to eq([1, 2])
@@ -174,8 +191,8 @@ describe Ramda::Object do
174
191
  it 'from docs' do
175
192
  pred = R.where(a: R.equals('foo'),
176
193
  b: R.complement(R.equals('bar')),
177
- x: R.lt(10),
178
- y: R.gt(20))
194
+ x: R.gt(R.__, 10),
195
+ y: R.lt(R.__, 20))
179
196
 
180
197
  expect(pred.call(a: 'foo', b: 'xxx', x: 11, y: 19)).to be_truthy
181
198
  expect(pred.call(a: 'xxx', b: 'xxx', x: 11, y: 19)).to be_falsey
@@ -11,6 +11,13 @@ describe Ramda::String do
11
11
  end
12
12
  end
13
13
 
14
+ context '#replace' do
15
+ it 'from docs' do
16
+ expect(r.replace('foo', 'bar', 'test foo foo foo')).to eq('test bar bar bar')
17
+ expect(r.replace(/foo/, 'bar', 'test foo foo foo')).to eq('test bar bar bar')
18
+ end
19
+ end
20
+
14
21
  context '#split' do
15
22
  it 'from docs' do
16
23
  path_components = r.split('/')
@@ -41,4 +48,11 @@ describe Ramda::String do
41
48
  expect(r.to_lower.call('XYZ')).to eq('xyz')
42
49
  end
43
50
  end
51
+
52
+ context '#trim' do
53
+ it 'from docs' do
54
+ expect(r.trim(' xyz ')).to eq('xyz')
55
+ expect(R.map(r.trim, R.split(',', 'x, y, z'))).to eq(['x', 'y', 'z'])
56
+ end
57
+ end
44
58
  end
data/spec/ramda_spec.rb CHANGED
@@ -11,6 +11,9 @@ describe Ramda do
11
11
  # r(:math_mod)
12
12
  # r(:to_pairs_in)
13
13
  # r(:values_in)
14
+ r(:F)
15
+ r(:T)
16
+ r(:__)
14
17
  r(:add)
15
18
  r(:all)
16
19
  r(:all_pass)
@@ -22,12 +25,14 @@ describe Ramda do
22
25
  r(:append)
23
26
  r(:assoc)
24
27
  r(:binary)
28
+ r(:bind)
25
29
  r(:chain)
26
30
  r(:clone)
27
31
  r(:comparator)
28
32
  r(:complement)
29
33
  r(:compose)
30
34
  r(:concat)
35
+ r(:cond)
31
36
  r(:construct)
32
37
  r(:construct_n)
33
38
  r(:contains)
@@ -102,6 +107,7 @@ describe Ramda do
102
107
  r(:project)
103
108
  r(:prop)
104
109
  r(:prop_eq)
110
+ r(:prop_or)
105
111
  r(:props)
106
112
  r(:range)
107
113
  r(:reduce)
@@ -109,6 +115,7 @@ describe Ramda do
109
115
  r(:reject)
110
116
  r(:remove)
111
117
  r(:repeat)
118
+ r(:replace)
112
119
  r(:reverse)
113
120
  r(:slice)
114
121
  r(:sort)
@@ -124,6 +131,7 @@ describe Ramda do
124
131
  r(:to_lower)
125
132
  r(:to_pairs)
126
133
  r(:to_upper)
134
+ r(:trim)
127
135
  r(:unary)
128
136
  r(:union)
129
137
  r(:union_with)
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.5.0
4
+ version: 0.6.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-20 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby version of Ramda Js library.
14
14
  email: