ramda-ruby 0.9.0 → 0.10.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 +17 -0
- data/README.md +29 -4
- data/ROADMAP.md +0 -13
- data/docs/FUNCTIONS.md +208 -164
- data/lib/ramda/function.rb +23 -3
- data/lib/ramda/internal/dispatchable.rb +28 -0
- data/lib/ramda/list.rb +156 -50
- data/lib/ramda/logic.rb +9 -0
- data/lib/ramda/version.rb +1 -1
- data/spec/ramda/function_spec.rb +28 -0
- data/spec/ramda/list_spec.rb +50 -0
- data/spec/ramda/logic_spec.rb +9 -0
- data/spec/ramda_spec.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65ad97e5bb00333847f6a7705f72b84ae81f7549
|
4
|
+
data.tar.gz: 2aab392d448af389c478cf44c1a3f5639d8948b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba02e63aeb102d71134428662f1eb7574bee6f6bb57e8befa70616272fc05d7e635b4023ceae1811232069abe9b2a83e4f1afc424e8cd7c4ee277a8954651a0
|
7
|
+
data.tar.gz: e9e6e79f2b65392162157d504813a20caa3116b9096f1e2c369d709b3c4c650b9039604f5840a02c6a33edcb18ba903305b27d1d05340c3c8549093c0237c2a6
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
Not Released
|
2
2
|
---------------
|
3
3
|
|
4
|
+
Release 0.10.0
|
5
|
+
---------------
|
6
|
+
|
7
|
+
Added:
|
8
|
+
|
9
|
+
* (pending) compose_p
|
10
|
+
* (pending) pipe_p
|
11
|
+
* (pending) map_accum
|
12
|
+
* (pending) map_accum_right
|
13
|
+
* default_to
|
14
|
+
* merge_all
|
15
|
+
* partial
|
16
|
+
* partial_right
|
17
|
+
* scan
|
18
|
+
* unfold
|
19
|
+
|
20
|
+
|
4
21
|
Release 0.9.0
|
5
22
|
---------------
|
6
23
|
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Ramda Ruby
|
|
4
4
|
This is a ruby version of [Ramda Js](http://ramdajs.com) library.
|
5
5
|
|
6
6
|
[](http://badge.fury.io/rb/ramda-ruby)
|
7
|
-
[](docs/FUNCTIONS.md)
|
8
8
|
[](https://travis-ci.org/lazebny/ramda-ruby)
|
9
9
|
[](https://ci.appveyor.com/project/lazebny/ramda-ruby)
|
10
10
|
[](https://coveralls.io/r/lazebny/ramda-ruby)
|
@@ -168,15 +168,40 @@ bundle exec rake ramda:run_benchmark_to_file[bench/list/*]
|
|
168
168
|
Development
|
169
169
|
--------------
|
170
170
|
|
171
|
-
|
171
|
+
You can use either regular approach with installing gems on local machine
|
172
|
+
or with docker-compose which is handy when you are playing with ruby versions.
|
172
173
|
|
173
|
-
|
174
|
+
With docker-compose:
|
175
|
+
|
176
|
+
1. Install [Docker](https://docs.docker.com/engine/installation/)
|
177
|
+
2. Install [Docker Compose](https://docs.docker.com/compose/install/)
|
178
|
+
3. Run tests
|
179
|
+
|
180
|
+
```sh
|
181
|
+
|
182
|
+
touch .bashrc.docker .pry_history.docker
|
183
|
+
docker-compose run --rm app bash
|
184
|
+
bundle
|
185
|
+
rspec
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
To release a new version, update the version number in `version.rb`,
|
190
|
+
and then run `bundle exec rake release`, which will create a git tag
|
191
|
+
for the version, push git commits and tags, and push the `.gem` file
|
192
|
+
to [rubygems.org](https://rubygems.org).
|
174
193
|
|
175
194
|
|
176
195
|
Contributing
|
177
196
|
--------------
|
178
197
|
|
179
|
-
|
198
|
+
1. Fork it
|
199
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
200
|
+
3. Make changes
|
201
|
+
4. Check with Rubocop and resolve all issues(`rubocop -aD`)
|
202
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
203
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
204
|
+
7. Create new Pull Request
|
180
205
|
|
181
206
|
|
182
207
|
License
|
data/ROADMAP.md
CHANGED
data/docs/FUNCTIONS.md
CHANGED
@@ -1,168 +1,212 @@
|
|
1
|
+
* (pending) compose_p
|
1
2
|
* (pending) keys_in
|
3
|
+
* (pending) map_accum
|
4
|
+
* (pending) map_accum_right
|
2
5
|
* (pending) math_mod
|
6
|
+
* (pending) pipe_p
|
3
7
|
* (pending) to_pairs_in
|
4
8
|
* (pending) values_in
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
*
|
49
|
-
*
|
50
|
-
*
|
51
|
-
*
|
52
|
-
*
|
53
|
-
*
|
54
|
-
*
|
55
|
-
*
|
56
|
-
*
|
57
|
-
*
|
58
|
-
*
|
59
|
-
*
|
60
|
-
*
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
*
|
67
|
-
*
|
68
|
-
*
|
69
|
-
*
|
70
|
-
*
|
71
|
-
*
|
72
|
-
*
|
73
|
-
*
|
74
|
-
*
|
75
|
-
*
|
76
|
-
*
|
77
|
-
*
|
78
|
-
*
|
79
|
-
*
|
80
|
-
*
|
81
|
-
*
|
82
|
-
*
|
83
|
-
*
|
84
|
-
*
|
85
|
-
*
|
86
|
-
*
|
87
|
-
*
|
88
|
-
*
|
89
|
-
*
|
90
|
-
*
|
91
|
-
*
|
92
|
-
*
|
93
|
-
*
|
94
|
-
*
|
95
|
-
*
|
96
|
-
*
|
97
|
-
*
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
101
|
-
*
|
102
|
-
*
|
103
|
-
*
|
104
|
-
*
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
*
|
110
|
-
*
|
111
|
-
*
|
112
|
-
*
|
113
|
-
*
|
114
|
-
*
|
115
|
-
*
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
*
|
124
|
-
*
|
125
|
-
*
|
126
|
-
*
|
127
|
-
*
|
128
|
-
*
|
129
|
-
*
|
130
|
-
*
|
131
|
-
*
|
132
|
-
*
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
*
|
138
|
-
*
|
139
|
-
*
|
140
|
-
*
|
141
|
-
*
|
142
|
-
*
|
143
|
-
*
|
144
|
-
*
|
145
|
-
*
|
146
|
-
*
|
147
|
-
*
|
148
|
-
*
|
149
|
-
*
|
150
|
-
*
|
151
|
-
*
|
152
|
-
*
|
153
|
-
*
|
154
|
-
*
|
155
|
-
*
|
156
|
-
*
|
157
|
-
*
|
158
|
-
*
|
159
|
-
*
|
160
|
-
*
|
161
|
-
*
|
162
|
-
*
|
163
|
-
*
|
164
|
-
*
|
165
|
-
*
|
166
|
-
*
|
167
|
-
*
|
168
|
-
|
9
|
+
|
10
|
+
Function
|
11
|
+
------------
|
12
|
+
|
13
|
+
* [F](http://ramdajs.com/docs/#F)
|
14
|
+
* [T](http://ramdajs.com/docs/#T)
|
15
|
+
* [`__`](http://ramdajs.com/docs/) - 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)`
|
16
|
+
* [always](http://ramdajs.com/docs/#always)
|
17
|
+
* [ap](http://ramdajs.com/docs/#ap)
|
18
|
+
* [apply](http://ramdajs.com/docs/#apply)
|
19
|
+
* [binary](http://ramdajs.com/docs/#binary)
|
20
|
+
* [bind](http://ramdajs.com/docs/#bind)
|
21
|
+
* [call](http://ramdajs.com/docs/#call)
|
22
|
+
* [comparator](http://ramdajs.com/docs/#comparator)
|
23
|
+
* [compose](http://ramdajs.com/docs/#compose)
|
24
|
+
* [construct](http://ramdajs.com/docs/#construct)
|
25
|
+
* [construct_n](http://ramdajs.com/docs/#constructN)
|
26
|
+
* [converge](http://ramdajs.com/docs/#converge)
|
27
|
+
* [curry](http://ramdajs.com/docs/#curry)
|
28
|
+
* [curry_n](http://ramdajs.com/docs/#curryN)
|
29
|
+
* [empty](http://ramdajs.com/docs/#empty) - uses x.class.new for defining new empty object if empty method does not exist
|
30
|
+
* [flip](http://ramdajs.com/docs/#flip)
|
31
|
+
* [identity](http://ramdajs.com/docs/#identity)
|
32
|
+
* [invoker](http://ramdajs.com/docs/#invoker)
|
33
|
+
* [juxt](http://ramdajs.com/docs/#juxt)
|
34
|
+
* [lift](http://ramdajs.com/docs/#lift)
|
35
|
+
* [lift_n](http://ramdajs.com/docs/#liftN)
|
36
|
+
* [memoize](http://ramdajs.com/docs/#memoize)
|
37
|
+
* [n_ary](http://ramdajs.com/docs/#nAry)
|
38
|
+
* [nth_arg](http://ramdajs.com/docs/#nthArg)
|
39
|
+
* [of](http://ramdajs.com/docs/#cond)
|
40
|
+
* [once](http://ramdajs.com/docs/#once)
|
41
|
+
* [partial](http://ramdajs.com/docs/#partial)
|
42
|
+
* [partial_right](http://ramdajs.com/docs/#partialRight)
|
43
|
+
* [pipe](http://ramdajs.com/docs/#pipe)
|
44
|
+
* [tap](http://ramdajs.com/docs/#tap)
|
45
|
+
* [unapply](http://ramdajs.com/docs/#unapply)
|
46
|
+
* [unary](http://ramdajs.com/docs/#unary)
|
47
|
+
* [use_with](http://ramdajs.com/docs/#useWith)
|
48
|
+
|
49
|
+
List
|
50
|
+
------------
|
51
|
+
|
52
|
+
* [all](http://ramdajs.com/docs/#all)
|
53
|
+
* [any](http://ramdajs.com/docs/#any)
|
54
|
+
* [append](http://ramdajs.com/docs/#append)
|
55
|
+
* [chain](http://ramdajs.com/docs/#chain)
|
56
|
+
* [concat](http://ramdajs.com/docs/#concat)
|
57
|
+
* [contains](http://ramdajs.com/docs/#contains)
|
58
|
+
* [drop](http://ramdajs.com/docs/#drop)
|
59
|
+
* [drop_while](http://ramdajs.com/docs/#dropWhile)
|
60
|
+
* [filter](http://ramdajs.com/docs/#filter)
|
61
|
+
* [find](http://ramdajs.com/docs/#find)
|
62
|
+
* [find_index](http://ramdajs.com/docs/#findIndex) - returns nil if index doesn't exist
|
63
|
+
* [find_last](http://ramdajs.com/docs/#findLast)
|
64
|
+
* [find_last_index](http://ramdajs.com/docs/#findLastIndex) - returns nil if index doesn't exist
|
65
|
+
* [flatten](http://ramdajs.com/docs/#flatten)
|
66
|
+
* [for_each](http://ramdajs.com/docs/#forEach)
|
67
|
+
* [from_pairs](http://ramdajs.com/docs/#fromPairs)
|
68
|
+
* [group_by](http://ramdajs.com/docs/#groupBy)
|
69
|
+
* [head](http://ramdajs.com/docs/#head)
|
70
|
+
* [index_of](http://ramdajs.com/docs/#indexOf) - returns nil if index doesn't exist
|
71
|
+
* [init](http://ramdajs.com/docs/#init)
|
72
|
+
* [insert](http://ramdajs.com/docs/#insert)
|
73
|
+
* [insert_all](http://ramdajs.com/docs/#insertAll)
|
74
|
+
* [join](http://ramdajs.com/docs/#join)
|
75
|
+
* [last](http://ramdajs.com/docs/#last)
|
76
|
+
* [last_index_of](http://ramdajs.com/docs/#lastIndexOf) - returns nil if index doesn't exist
|
77
|
+
* [length](http://ramdajs.com/docs/#length)
|
78
|
+
* [map](http://ramdajs.com/docs/#map)
|
79
|
+
* [map_obj_indexed](http://ramdajs.com/docs/#mapObjIndexed)
|
80
|
+
* [merge_all](http://ramdajs.com/docs/#mergeAll)
|
81
|
+
* [nth](http://ramdajs.com/docs/#nth)
|
82
|
+
* [partition](http://ramdajs.com/docs/#partition)
|
83
|
+
* [pluck](http://ramdajs.com/docs/#pluck)
|
84
|
+
* [prepend](http://ramdajs.com/docs/#prepend)
|
85
|
+
* [range](http://ramdajs.com/docs/#range)
|
86
|
+
* [reduce](http://ramdajs.com/docs/#reduce)
|
87
|
+
* [reduce_right](http://ramdajs.com/docs/#reduceRight)
|
88
|
+
* [reject](http://ramdajs.com/docs/#reject)
|
89
|
+
* [remove](http://ramdajs.com/docs/#remove)
|
90
|
+
* [repeat](http://ramdajs.com/docs/#repeat)
|
91
|
+
* [reverse](http://ramdajs.com/docs/#reverse)
|
92
|
+
* [scan](http://ramdajs.com/docs/#scan)
|
93
|
+
* [slice](http://ramdajs.com/docs/#slice)
|
94
|
+
* [sort](http://ramdajs.com/docs/#sort)
|
95
|
+
* [sort_by](http://ramdajs.com/docs/#sortBy)
|
96
|
+
* [tail](http://ramdajs.com/docs/#tail)
|
97
|
+
* [take](http://ramdajs.com/docs/#take)
|
98
|
+
* [take_while](http://ramdajs.com/docs/#takeWhile)
|
99
|
+
* [times](http://ramdajs.com/docs/#times)
|
100
|
+
* [unfold](http://ramdajs.com/docs/#unfold)
|
101
|
+
* [uniq](http://ramdajs.com/docs/#uniq)
|
102
|
+
* [uniq_with](http://ramdajs.com/docs/#uniqWith) - first argument is a function with 1 arity which transforms each list element and applies uniq function to results
|
103
|
+
* [unnest](http://ramdajs.com/docs/#unnest)
|
104
|
+
* [update](http://ramdajs.com/docs/#update)
|
105
|
+
* [xprod](http://ramdajs.com/docs/#xprod)
|
106
|
+
* [zip](http://ramdajs.com/docs/#zip)
|
107
|
+
* [zip_obj](http://ramdajs.com/docs/#zipObj)
|
108
|
+
* [zip_with](http://ramdajs.com/docs/#zipWith)
|
109
|
+
|
110
|
+
Logic
|
111
|
+
------------
|
112
|
+
|
113
|
+
* [all_pass](http://ramdajs.com/docs/#allPass)
|
114
|
+
* [and](http://ramdajs.com/docs/#and)
|
115
|
+
* [any_pass](http://ramdajs.com/docs/#anyPass)
|
116
|
+
* [complement](http://ramdajs.com/docs/#complement)
|
117
|
+
* [cond](http://ramdajs.com/docs/#cond)
|
118
|
+
* [default_to](http://ramdajs.com/docs/#defaultTo)
|
119
|
+
* [if_else](http://ramdajs.com/docs/#ifElse)
|
120
|
+
* [is_empty](http://ramdajs.com/docs/#isEmpty)
|
121
|
+
* [not](http://ramdajs.com/docs/#not)
|
122
|
+
* [or](http://ramdajs.com/docs/#or)
|
123
|
+
|
124
|
+
Math
|
125
|
+
------------
|
126
|
+
|
127
|
+
* [add](http://ramdajs.com/docs/#add)
|
128
|
+
* [dec](http://ramdajs.com/docs/#dec)
|
129
|
+
* [divide](http://ramdajs.com/docs/#divide)
|
130
|
+
* [inc](http://ramdajs.com/docs/#inc)
|
131
|
+
* [modulo](http://ramdajs.com/docs/#modulo)
|
132
|
+
* [multiply](http://ramdajs.com/docs/#multiply)
|
133
|
+
* [negate](http://ramdajs.com/docs/#negate)
|
134
|
+
* [product](http://ramdajs.com/docs/#product)
|
135
|
+
* [subtract](http://ramdajs.com/docs/#substract)
|
136
|
+
* [sum](http://ramdajs.com/docs/#sum)
|
137
|
+
|
138
|
+
Object
|
139
|
+
------------
|
140
|
+
|
141
|
+
* [assoc](http://ramdajs.com/docs/#assoc)
|
142
|
+
* [assoc_path](http://ramdajs.com/docs/#assocPath)
|
143
|
+
* [clone](http://ramdajs.com/docs/#clone)
|
144
|
+
* [dissoc](http://ramdajs.com/docs/#dissoc)
|
145
|
+
* [eq_props](http://ramdajs.com/docs/#eqProps)
|
146
|
+
* [evolve](http://ramdajs.com/docs/#evolve)
|
147
|
+
* [has](http://ramdajs.com/docs/#has)
|
148
|
+
* [has_in](http://ramdajs.com/docs/#hasIn)
|
149
|
+
* [invert](http://ramdajs.com/docs/#invert)
|
150
|
+
* [invert_obj](http://ramdajs.com/docs/#invertObj)
|
151
|
+
* [keys](http://ramdajs.com/docs/#keys)
|
152
|
+
* [lens](http://ramdajs.com/docs/#lens) - composition does not work compose(lens1, lensb)
|
153
|
+
* [lens_index](http://ramdajs.com/docs/#lensIndex)
|
154
|
+
* [lens_path](http://ramdajs.com/docs/#lensPath)
|
155
|
+
* [lens_prop](http://ramdajs.com/docs/#lensProp)
|
156
|
+
* [merge](http://ramdajs.com/docs/#merge)
|
157
|
+
* [omit](http://ramdajs.com/docs/#omit)
|
158
|
+
* [over](http://ramdajs.com/docs/#over)
|
159
|
+
* [path](http://ramdajs.com/docs/#path)
|
160
|
+
* [pick](http://ramdajs.com/docs/#pick)
|
161
|
+
* [pick_all](http://ramdajs.com/docs/#pickAll)
|
162
|
+
* [pick_by](http://ramdajs.com/docs/#pickBy)
|
163
|
+
* [project](http://ramdajs.com/docs/#project)
|
164
|
+
* [prop](http://ramdajs.com/docs/#prop)
|
165
|
+
* [prop_or](http://ramdajs.com/docs/#propOr)
|
166
|
+
* [props](http://ramdajs.com/docs/#props)
|
167
|
+
* [set](http://ramdajs.com/docs/#set)
|
168
|
+
* [to_pairs](http://ramdajs.com/docs/#toPairs)
|
169
|
+
* [values](http://ramdajs.com/docs/#values)
|
170
|
+
* [view](http://ramdajs.com/docs/#view)
|
171
|
+
* [where](http://ramdajs.com/docs/#where)
|
172
|
+
|
173
|
+
|
174
|
+
Relation
|
175
|
+
------------
|
176
|
+
|
177
|
+
* [count_by](http://ramdajs.com/docs/#countBy)
|
178
|
+
* [difference](http://ramdajs.com/docs/#difference)
|
179
|
+
* [difference_with](http://ramdajs.com/docs/#differenceWith)
|
180
|
+
* [eq_by](http://ramdajs.com/docs/#eqBy)
|
181
|
+
* [equals](http://ramdajs.com/docs/#equals)
|
182
|
+
* [gt](http://ramdajs.com/docs/#gt)
|
183
|
+
* [gte](http://ramdajs.com/docs/#gte)
|
184
|
+
* [intersection](http://ramdajs.com/docs/#intersection)
|
185
|
+
* [lt](http://ramdajs.com/docs/#lt)
|
186
|
+
* [lte](http://ramdajs.com/docs/#lte)
|
187
|
+
* [max](http://ramdajs.com/docs/#max)
|
188
|
+
* [max_by](http://ramdajs.com/docs/#maxBy)
|
189
|
+
* [min](http://ramdajs.com/docs/#min)
|
190
|
+
* [min_by](http://ramdajs.com/docs/#minBy)
|
191
|
+
* [path_eq](http://ramdajs.com/docs/#pathEq)
|
192
|
+
* [prop_eq](http://ramdajs.com/docs/#propEq)
|
193
|
+
* [sort_by](http://ramdajs.com/docs/#sortBy)
|
194
|
+
* [union](http://ramdajs.com/docs/#union)
|
195
|
+
* [union_with](http://ramdajs.com/docs/#unionWith)
|
196
|
+
|
197
|
+
String
|
198
|
+
------------
|
199
|
+
|
200
|
+
* [match](http://ramdajs.com/docs/#math)
|
201
|
+
* [replace](http://ramdajs.com/docs/#replace) - it uses a gsub method and global replacement
|
202
|
+
* [split](http://ramdajs.com/docs/#split)
|
203
|
+
* [to_lower](http://ramdajs.com/docs/#toLower)
|
204
|
+
* [to_upper](http://ramdajs.com/docs/#toUpper)
|
205
|
+
* [trim](http://ramdajs.com/docs/#trim)
|
206
|
+
|
207
|
+
Type
|
208
|
+
------------
|
209
|
+
|
210
|
+
* [is](http://ramdajs.com/docs/#is)
|
211
|
+
* [is_nil](http://ramdajs.com/docs/#isNil)
|
212
|
+
* [type](http://ramdajs.com/docs/#type)
|
data/lib/ramda/function.rb
CHANGED
@@ -27,10 +27,10 @@ module Ramda
|
|
27
27
|
# Apply f => f (a -> b) -> f a -> f b
|
28
28
|
#
|
29
29
|
curried_method(:ap) do |apply_f, apply_x|
|
30
|
-
if apply_x.
|
31
|
-
apply_x.ap(apply_f)
|
32
|
-
else
|
30
|
+
if apply_x.is_a?(Array)
|
33
31
|
apply_f.flat_map { |fn| apply_x.map(&fn) }
|
32
|
+
else
|
33
|
+
Internal::Dispatchable.call([:ap], nil, apply_f, apply_x)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -308,6 +308,26 @@ module Ramda
|
|
308
308
|
end.curry
|
309
309
|
end
|
310
310
|
|
311
|
+
# Takes a function f and a list of arguments, and returns a function g.
|
312
|
+
# When applied, g returns the result of applying f to the arguments
|
313
|
+
# provided initially followed by the arguments provided to g.
|
314
|
+
#
|
315
|
+
# ((a, b, c, ..., n) -> x) -> [a, b, c, ...] -> ((d, e, f, ..., n) -> x)
|
316
|
+
#
|
317
|
+
curried_method(:partial) do |fn, args|
|
318
|
+
Ramda.curry(fn).call(*args)
|
319
|
+
end
|
320
|
+
|
321
|
+
# Takes a function f and a list of arguments, and returns a function g.
|
322
|
+
# When applied, g returns the result of applying f to the arguments
|
323
|
+
# provided to g followed by the arguments provided initially.
|
324
|
+
#
|
325
|
+
# ((a, b, c, ..., n) -> x) -> [d, e, f, ..., n] -> ((a, b, c, ...) -> x)
|
326
|
+
#
|
327
|
+
curried_method(:partial_right) do |fn, args|
|
328
|
+
Ramda.curry(fn).call(*Array.new(fn.arity - args.size, Ramda.__) + args)
|
329
|
+
end
|
330
|
+
|
311
331
|
# Performs left-to-right function composition. The leftmost function may
|
312
332
|
# have any arity; the remaining functions must be unary.
|
313
333
|
# In some libraries this function is named sequence.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ramda
|
2
|
+
module Internal
|
3
|
+
# Dispatchable
|
4
|
+
module Dispatchable
|
5
|
+
#
|
6
|
+
# Returns a function that dispatches with different strategies based on the
|
7
|
+
# object in list position (last argument). If it is an array, executes [fn].
|
8
|
+
# Otherwise, if it has a function with [methodname], it will execute that
|
9
|
+
# function (functor case). Otherwise, if it is a transformer, uses transducer
|
10
|
+
# [xf] to return a new transformer (transducer case). Otherwise, it will
|
11
|
+
# default to executing [fn].
|
12
|
+
#
|
13
|
+
# @private
|
14
|
+
# - @param {String} methodname property to check for a custom implementation
|
15
|
+
# - @param {Function} xf transducer to initialize if object is transformer
|
16
|
+
# - @param {Function} fn default ramda implementation
|
17
|
+
# - @return {Function} A function that dispatches on object in list position
|
18
|
+
#
|
19
|
+
def self.call(method_names, _xf, *args, xs)
|
20
|
+
method_name = method_names.find { |name| xs.respond_to?(name) }
|
21
|
+
|
22
|
+
return xs.public_send(method_name, *args) if method_name
|
23
|
+
|
24
|
+
raise ArgumentError, "Unexpected type #{xs.class} in method: #{method_name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ramda/list.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'internal/curried_method'
|
2
|
+
require_relative 'internal/dispatchable'
|
2
3
|
|
3
4
|
module Ramda
|
4
5
|
# List functions
|
@@ -8,24 +9,36 @@ module Ramda
|
|
8
9
|
|
9
10
|
# Returns true if all elements of the list match the predicate,
|
10
11
|
# false if there are any that don't.
|
12
|
+
#
|
11
13
|
# Dispatches to the all method of the second argument, if present.
|
14
|
+
#
|
12
15
|
# Acts as a transducer if a transformer is given in list position.
|
13
16
|
#
|
14
17
|
# (a -> Boolean) -> [a] -> Boolean
|
15
18
|
#
|
16
19
|
curried_method(:all) do |f, xs|
|
17
|
-
xs.
|
20
|
+
if xs.is_a?(::Array)
|
21
|
+
xs.all?(&f)
|
22
|
+
else
|
23
|
+
Internal::Dispatchable.call([:any], nil, f, xs)
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
# Returns true if at least one of elements of the list match the predicate,
|
21
28
|
# false otherwise.
|
29
|
+
#
|
22
30
|
# Dispatches to the any method of the second argument, if present.
|
31
|
+
#
|
23
32
|
# Acts as a transducer if a transformer is given in list position.
|
24
33
|
#
|
25
34
|
# (a -> Boolean) -> [a] -> Boolean
|
26
35
|
#
|
27
36
|
curried_method(:any) do |f, xs|
|
28
|
-
xs.
|
37
|
+
if xs.is_a?(::Array)
|
38
|
+
xs.any?(&f)
|
39
|
+
else
|
40
|
+
Internal::Dispatchable.call([:any], nil, f, xs)
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
# Returns a new list containing the contents of the given list,
|
@@ -45,13 +58,11 @@ module Ramda
|
|
45
58
|
#
|
46
59
|
# Chain m => (a -> m b) -> m a -> m b
|
47
60
|
#
|
48
|
-
curried_method(:chain) do |
|
49
|
-
if xs.
|
50
|
-
xs.
|
51
|
-
elsif xs.respond_to?(:bind)
|
52
|
-
xs.bind(fn)
|
61
|
+
curried_method(:chain) do |f, xs|
|
62
|
+
if xs.is_a?(::Array)
|
63
|
+
xs.flat_map(&f)
|
53
64
|
else
|
54
|
-
|
65
|
+
Internal::Dispatchable.call([:chain, :bind], nil, f, xs)
|
55
66
|
end
|
56
67
|
end
|
57
68
|
|
@@ -61,19 +72,21 @@ module Ramda
|
|
61
72
|
# List -> List -> List
|
62
73
|
#
|
63
74
|
curried_method(:concat) do |list_a, list_b|
|
64
|
-
case
|
75
|
+
case list_b
|
65
76
|
when ::String, ::Symbol
|
66
77
|
[list_a, list_b].join('')
|
67
78
|
when ::Array
|
68
79
|
list_a.dup + list_b
|
69
80
|
else
|
70
|
-
|
81
|
+
Internal::Dispatchable.call([:concat], nil, list_a, list_b)
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
74
85
|
# Returns true if the specified value is equal, in R.equals terms,
|
75
86
|
# to at least one element of the given list; false otherwise.
|
76
87
|
#
|
88
|
+
# Dispatches to the concat method of the first argument, if present.
|
89
|
+
#
|
77
90
|
# a -> [a] -> Boolean
|
78
91
|
#
|
79
92
|
curried_method(:contains) do |x, xs|
|
@@ -83,6 +96,8 @@ module Ramda
|
|
83
96
|
# Returns all but the first n elements of the given list, string,
|
84
97
|
# or transducer/transformer (or object with a drop method).
|
85
98
|
#
|
99
|
+
# Dispatches to the drop method of the second argument, if present.
|
100
|
+
#
|
86
101
|
# Number -> [a] -> [a]
|
87
102
|
# Number -> String -> String
|
88
103
|
#
|
@@ -93,7 +108,7 @@ module Ramda
|
|
93
108
|
when ::Array
|
94
109
|
xs[num..-1] || []
|
95
110
|
else
|
96
|
-
|
111
|
+
Internal::Dispatchable.call([:drop], nil, num, xs)
|
97
112
|
end
|
98
113
|
end
|
99
114
|
|
@@ -109,14 +124,19 @@ module Ramda
|
|
109
124
|
#
|
110
125
|
# (a -> Boolean) -> [a] -> [a]
|
111
126
|
#
|
112
|
-
curried_method(:drop_while) do |
|
113
|
-
xs.
|
127
|
+
curried_method(:drop_while) do |f, xs|
|
128
|
+
if xs.is_a?(::Array)
|
129
|
+
xs.drop_while(&f)
|
130
|
+
else
|
131
|
+
Internal::Dispatchable.call([:drop_while], nil, f, xs)
|
132
|
+
end
|
114
133
|
end
|
115
134
|
|
116
135
|
# Takes a predicate and a Filterable, and returns a new filterable of the same
|
117
136
|
# type containing the members of the given filterable which satisfy the given
|
118
137
|
# predicate. Filterable objects include plain objects or any object that
|
119
138
|
# has a filter method such as Array.
|
139
|
+
#
|
120
140
|
# Dispatches to the filter method of the second argument, if present.
|
121
141
|
#
|
122
142
|
# Filterable f => (a -> Boolean) -> f a -> f a
|
@@ -125,8 +145,10 @@ module Ramda
|
|
125
145
|
case xs
|
126
146
|
when ::Hash
|
127
147
|
xs.select { |_, value| f.call(value) }
|
128
|
-
|
148
|
+
when ::Array
|
129
149
|
xs.select(&f)
|
150
|
+
else
|
151
|
+
Internal::Dispatchable.call([:filter], nil, f, xs)
|
130
152
|
end
|
131
153
|
end
|
132
154
|
|
@@ -142,10 +164,16 @@ module Ramda
|
|
142
164
|
# Returns the first element of the list which matches the predicate,
|
143
165
|
# or undefined if no element matches.
|
144
166
|
#
|
167
|
+
# Dispatches to the find method of the second argument, if present.
|
168
|
+
#
|
145
169
|
# (a -> Boolean) -> [a] -> a | NilClass
|
146
170
|
#
|
147
171
|
curried_method(:find) do |f, xs|
|
148
|
-
xs.
|
172
|
+
if xs.is_a?(::Array)
|
173
|
+
xs.find(&f)
|
174
|
+
else
|
175
|
+
Internal::Dispatchable.call([:find], nil, f, xs)
|
176
|
+
end
|
149
177
|
end
|
150
178
|
|
151
179
|
# Returns the index of the first element of the list which matches the predicate,
|
@@ -153,8 +181,8 @@ module Ramda
|
|
153
181
|
#
|
154
182
|
# (a -> Boolean) -> [a] -> Number | NilClass
|
155
183
|
#
|
156
|
-
curried_method(:find_index) do |
|
157
|
-
xs.index(&
|
184
|
+
curried_method(:find_index) do |f, xs|
|
185
|
+
xs.index(&f)
|
158
186
|
end
|
159
187
|
|
160
188
|
# Returns the last element of the list which matches the predicate,
|
@@ -162,8 +190,8 @@ module Ramda
|
|
162
190
|
#
|
163
191
|
# (a -> Boolean) -> [a] -> a | NilClass
|
164
192
|
#
|
165
|
-
curried_method(:find_last) do |
|
166
|
-
index = xs.rindex(&
|
193
|
+
curried_method(:find_last) do |f, xs|
|
194
|
+
index = xs.rindex(&f)
|
167
195
|
xs[index] unless index.nil?
|
168
196
|
end
|
169
197
|
|
@@ -172,8 +200,8 @@ module Ramda
|
|
172
200
|
#
|
173
201
|
# (a -> Boolean) -> [a] -> Number | NilClass
|
174
202
|
#
|
175
|
-
curried_method(:find_last_index) do |
|
176
|
-
xs.rindex(&
|
203
|
+
curried_method(:find_last_index) do |f, xs|
|
204
|
+
xs.rindex(&f)
|
177
205
|
end
|
178
206
|
|
179
207
|
# Returns a new list by pulling every item out of it (and all its sub-arrays)
|
@@ -186,20 +214,33 @@ module Ramda
|
|
186
214
|
# Iterate over an input list, calling a provided function fn for each element
|
187
215
|
# in the list.
|
188
216
|
#
|
217
|
+
# Dispatches to the forEach method of the second argument, if present.
|
218
|
+
#
|
189
219
|
# (a -> *) -> [a] -> [a]
|
190
220
|
#
|
191
|
-
curried_method(:for_each) do |
|
192
|
-
xs.
|
221
|
+
curried_method(:for_each) do |f, xs|
|
222
|
+
if xs.is_a?(::Array)
|
223
|
+
xs.each(&f)
|
224
|
+
else
|
225
|
+
Internal::Dispatchable.call([:for_each], nil, f, xs)
|
226
|
+
end
|
193
227
|
end
|
194
228
|
|
195
229
|
# Splits a list into sub-lists stored in an object, based on the result of
|
196
230
|
# calling a String-returning function on each element, and grouping the
|
197
231
|
# results according to values returned.
|
198
232
|
#
|
233
|
+
# Dispatches to the groupBy method of the second argument, if present.
|
234
|
+
#
|
235
|
+
#
|
199
236
|
# (a -> String) -> [a] -> {String: [a]}
|
200
237
|
#
|
201
238
|
curried_method(:group_by) do |f, xs|
|
202
|
-
xs.
|
239
|
+
if xs.is_a?(::Array)
|
240
|
+
xs.group_by(&f)
|
241
|
+
else
|
242
|
+
Internal::Dispatchable.call([:group_by], nil, f, xs)
|
243
|
+
end
|
203
244
|
end
|
204
245
|
|
205
246
|
# Returns the first element of the given list or string. In some libraries
|
@@ -297,21 +338,39 @@ module Ramda
|
|
297
338
|
#
|
298
339
|
# Functor f => (a -> b) -> f a -> f b
|
299
340
|
#
|
300
|
-
curried_method(:map) do |f,
|
301
|
-
case
|
341
|
+
curried_method(:map) do |f, xs|
|
342
|
+
case xs
|
302
343
|
when ::Hash
|
303
|
-
Hash[
|
344
|
+
Hash[xs.map { |k, v| [k, f.call(v)] }]
|
304
345
|
when ::Array
|
305
|
-
|
346
|
+
xs.map(&f)
|
306
347
|
else
|
307
|
-
|
308
|
-
functor.map(f)
|
309
|
-
else
|
310
|
-
type_error(functor, :map)
|
311
|
-
end
|
348
|
+
Internal::Dispatchable.call([:map], nil, f, xs)
|
312
349
|
end
|
313
350
|
end
|
314
351
|
|
352
|
+
# The mapAccum function behaves like a combination of map and reduce;
|
353
|
+
# it applies a function to each element of a list, passing
|
354
|
+
# an accumulating parameter from left to right, and returning
|
355
|
+
# a final value of this accumulator together with the new list.
|
356
|
+
#
|
357
|
+
# The iterator function receives two arguments, acc and value,
|
358
|
+
# and should return a tuple [acc, value].
|
359
|
+
#
|
360
|
+
# (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
|
361
|
+
#
|
362
|
+
# curried_method(:map_accum) do |fn, acc, xs|
|
363
|
+
#
|
364
|
+
# end
|
365
|
+
|
366
|
+
# Merges a list of objects together into one object.
|
367
|
+
#
|
368
|
+
# [{k: v}] -> {k: v}
|
369
|
+
#
|
370
|
+
curried_method(:merge_all) do |xs|
|
371
|
+
xs.reduce(&:merge)
|
372
|
+
end
|
373
|
+
|
315
374
|
# Returns the nth element of the given list or string. If n is negative
|
316
375
|
# the element at index length + n is returned.
|
317
376
|
#
|
@@ -335,8 +394,8 @@ module Ramda
|
|
335
394
|
#
|
336
395
|
# Filterable f => (a -> Boolean) -> f a -> [f a, f a]
|
337
396
|
#
|
338
|
-
curried_method(:partition) do |
|
339
|
-
::Ramda.juxt([::Ramda.filter, ::Ramda.reject]).call(
|
397
|
+
curried_method(:partition) do |f, xs|
|
398
|
+
::Ramda.juxt([::Ramda.filter, ::Ramda.reject]).call(f, xs)
|
340
399
|
end
|
341
400
|
|
342
401
|
# Returns a new list by plucking the same named property off all objects
|
@@ -378,8 +437,8 @@ module Ramda
|
|
378
437
|
#
|
379
438
|
# ((a, b) -> a) -> a -> [b] -> a
|
380
439
|
#
|
381
|
-
curried_method(:reduce) do |
|
382
|
-
xs.reduce(acc, &
|
440
|
+
curried_method(:reduce) do |f, acc, xs|
|
441
|
+
xs.reduce(acc, &f)
|
383
442
|
end
|
384
443
|
|
385
444
|
# Returns a single item by iterating through the list, successively
|
@@ -394,8 +453,8 @@ module Ramda
|
|
394
453
|
#
|
395
454
|
# ((a, b) -> a) -> a -> [b] -> a
|
396
455
|
#
|
397
|
-
curried_method(:reduce_right) do |
|
398
|
-
xs.reverse.reduce(acc_arg) { |acc, x|
|
456
|
+
curried_method(:reduce_right) do |f, acc_arg, xs|
|
457
|
+
xs.reverse.reduce(acc_arg) { |acc, x| f.call(x, acc) }
|
399
458
|
end
|
400
459
|
|
401
460
|
# Returns a new list or string with the elements or characters in reverse order.
|
@@ -430,7 +489,16 @@ module Ramda
|
|
430
489
|
# a -> n -> [a]
|
431
490
|
#
|
432
491
|
curried_method(:repeat) do |a, n|
|
433
|
-
Array.new(n, a)
|
492
|
+
::Array.new(n, a)
|
493
|
+
end
|
494
|
+
|
495
|
+
# Scan is similar to reduce, but returns a list of successively
|
496
|
+
# reduced values from the left
|
497
|
+
#
|
498
|
+
# (a,b -> a) -> a -> [b] -> [a]
|
499
|
+
#
|
500
|
+
curried_method(:scan) do |f, acc0, xs|
|
501
|
+
xs.reduce([acc0]) { |acc, x| acc << f.call(acc[-1], x) }
|
434
502
|
end
|
435
503
|
|
436
504
|
# Returns the elements of the given list or string
|
@@ -440,7 +508,12 @@ module Ramda
|
|
440
508
|
# Number -> Number -> String -> String
|
441
509
|
#
|
442
510
|
curried_method(:slice) do |from, to, xs|
|
443
|
-
xs
|
511
|
+
case xs
|
512
|
+
when ::Array, ::String
|
513
|
+
xs[from...to]
|
514
|
+
else
|
515
|
+
Internal::Dispatchable.call([:slice], nil, from, to, xs)
|
516
|
+
end
|
444
517
|
end
|
445
518
|
|
446
519
|
# Returns a copy of the list, sorted according to the comparator function,
|
@@ -465,11 +538,18 @@ module Ramda
|
|
465
538
|
|
466
539
|
# Returns the first n elements of the given list, string.
|
467
540
|
#
|
541
|
+
# Dispatches to the take method of the second argument, if present.
|
542
|
+
#
|
468
543
|
# Number -> [a] -> [a]
|
469
544
|
# Number -> String -> String
|
470
545
|
#
|
471
546
|
curried_method(:take) do |num, xs|
|
472
|
-
xs
|
547
|
+
case xs
|
548
|
+
when ::Array, ::String
|
549
|
+
xs[0, num]
|
550
|
+
else
|
551
|
+
Internal::Dispatchable.call([:take], nil, num, xs)
|
552
|
+
end
|
473
553
|
end
|
474
554
|
|
475
555
|
# Returns a new list containing the first n elements of a given list,
|
@@ -480,8 +560,12 @@ module Ramda
|
|
480
560
|
#
|
481
561
|
# (a -> Boolean) -> [a] -> [a]
|
482
562
|
#
|
483
|
-
curried_method(:take_while) do |
|
484
|
-
|
563
|
+
curried_method(:take_while) do |f, xs|
|
564
|
+
if xs.is_a?(::Array)
|
565
|
+
xs[0, xs.index { |x| !f.call(x) } || xs.size]
|
566
|
+
else
|
567
|
+
Internal::Dispatchable.call([:take_while], nil, f, xs)
|
568
|
+
end
|
485
569
|
end
|
486
570
|
|
487
571
|
# Calls an input function n times, returning an array containing the results
|
@@ -491,8 +575,30 @@ module Ramda
|
|
491
575
|
#
|
492
576
|
# (Number -> a) -> Number -> [a]
|
493
577
|
#
|
494
|
-
curried_method(:times) do |
|
495
|
-
n.times.to_a.map(&
|
578
|
+
curried_method(:times) do |f, n|
|
579
|
+
n.times.to_a.map(&f)
|
580
|
+
end
|
581
|
+
|
582
|
+
# Builds a list from a seed value. Accepts an iterator function, which
|
583
|
+
# returns either false to stop iteration or an array of length 2
|
584
|
+
# containing the value to add to the resulting list and the seed
|
585
|
+
# to be used in the next call to the iterator function.
|
586
|
+
#
|
587
|
+
# The iterator function receives one argument: (seed).
|
588
|
+
#
|
589
|
+
# (a -> [b]) -> * -> [b]
|
590
|
+
#
|
591
|
+
curried_method(:unfold) do |f, n|
|
592
|
+
xs = []
|
593
|
+
loop do
|
594
|
+
res = f.call(n)
|
595
|
+
|
596
|
+
break if res.is_a?(FalseClass)
|
597
|
+
|
598
|
+
xs << res[0]
|
599
|
+
n = res[1]
|
600
|
+
end
|
601
|
+
xs
|
496
602
|
end
|
497
603
|
|
498
604
|
# Returns a new list containing only one copy of each element in the original list.
|
@@ -504,8 +610,8 @@ module Ramda
|
|
504
610
|
# Returns a new list containing only one copy of each element in the original list,
|
505
611
|
# based upon the value returned by applying the supplied predicate to each list
|
506
612
|
# element.
|
507
|
-
curried_method(:uniq_with) do |
|
508
|
-
xs.uniq(&
|
613
|
+
curried_method(:uniq_with) do |f, xs|
|
614
|
+
xs.uniq(&f)
|
509
615
|
end
|
510
616
|
|
511
617
|
# Shorthand for R.chain(R.identity), which removes one level of nesting from any Chain.
|
@@ -561,8 +667,8 @@ module Ramda
|
|
561
667
|
#
|
562
668
|
# (a,b -> c) -> [a] -> [b] -> [c]
|
563
669
|
#
|
564
|
-
curried_method(:zip_with) do |
|
565
|
-
xs1.zip(xs2).map { |(a, b)|
|
670
|
+
curried_method(:zip_with) do |f, xs1, xs2|
|
671
|
+
xs1.zip(xs2).map { |(a, b)| f.call(a, b) }
|
566
672
|
end
|
567
673
|
|
568
674
|
# TODO: Extract from this module
|
data/lib/ramda/logic.rb
CHANGED
@@ -47,6 +47,15 @@ module Ramda
|
|
47
47
|
then_fn.call(x, *other_x) unless then_fn.nil?
|
48
48
|
end
|
49
49
|
|
50
|
+
# Returns the second argument if it is not null, undefined or NaN;
|
51
|
+
# otherwise the first argument is returned.
|
52
|
+
#
|
53
|
+
# a -> b -> a | b
|
54
|
+
#
|
55
|
+
curried_method(:default_to) do |a, b|
|
56
|
+
b || a
|
57
|
+
end
|
58
|
+
|
50
59
|
# Creates a function that will process either the onTrue or the onFalse
|
51
60
|
# function depending upon the result of the condition predicate.
|
52
61
|
#
|
data/lib/ramda/version.rb
CHANGED
data/spec/ramda/function_spec.rb
CHANGED
@@ -407,6 +407,34 @@ describe Ramda::Function do
|
|
407
407
|
end
|
408
408
|
end
|
409
409
|
|
410
|
+
context '#partial' do
|
411
|
+
it 'from docs' do
|
412
|
+
multiply2 = ->(a, b) { a * b }
|
413
|
+
double_fn = R.partial(multiply2, [2])
|
414
|
+
expect(double_fn.call(2)).to eq(4)
|
415
|
+
|
416
|
+
greet = lambda { |salutation, title, first_name, last_name|
|
417
|
+
salutation + ', ' + title + ' ' + first_name + ' ' + last_name + '!'
|
418
|
+
}
|
419
|
+
|
420
|
+
say_hello = R.partial(greet, ['Hello'])
|
421
|
+
say_hello_to_ms = R.partial(say_hello, ['Ms.'])
|
422
|
+
expect(say_hello_to_ms.call('Jane', 'Jones')).to eq('Hello, Ms. Jane Jones!')
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context '#partial_right' do
|
427
|
+
it 'from docs' do
|
428
|
+
greet = lambda { |salutation, title, first_name, last_name|
|
429
|
+
salutation + ', ' + title + ' ' + first_name + ' ' + last_name + '!'
|
430
|
+
}
|
431
|
+
|
432
|
+
gree_ms_jane_jones = R.partial_right(greet, ['Ms.', 'Jane', 'Jones'])
|
433
|
+
|
434
|
+
expect(gree_ms_jane_jones.call('Hello')).to eq('Hello, Ms. Jane Jones!')
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
410
438
|
context '#pipe' do
|
411
439
|
it 'from docs' do
|
412
440
|
classy_greeting = lambda do |first_name, last_name|
|
data/spec/ramda/list_spec.rb
CHANGED
@@ -350,6 +350,26 @@ describe Ramda::List do
|
|
350
350
|
end
|
351
351
|
end
|
352
352
|
|
353
|
+
# context '#map_accum' do
|
354
|
+
# it 'from docs' do
|
355
|
+
# digits = ['1', '2', '3', '4'];
|
356
|
+
# appender = -> (a, b) { [a + b, a + b] }
|
357
|
+
#
|
358
|
+
# expect(R.map_accum(appender, 0, digits)).to eq(['01234', ['01', '012', '0123', '01234']])
|
359
|
+
# end
|
360
|
+
# end
|
361
|
+
|
362
|
+
context '#merge_all' do
|
363
|
+
it 'from docs' do
|
364
|
+
expect(R.merge_all([{ foo: 1 }, { bar: 2 }, { baz: 3 }])).to eq(foo: 1, bar: 2, baz: 3)
|
365
|
+
expect(R.merge_all([{ foo: 1 }, { foo: 2 }, { bar: 2 }])).to eq(foo: 2, bar: 2)
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'curried' do
|
369
|
+
expect(R.merge_all.call([{ foo: 1 }, { bar: 2 }])).to eq(foo: 1, bar: 2)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
353
373
|
context '#nth' do
|
354
374
|
it 'with array' do
|
355
375
|
list = ['foo', 'bar', 'baz', 'quux']
|
@@ -469,6 +489,29 @@ describe Ramda::List do
|
|
469
489
|
end
|
470
490
|
end
|
471
491
|
|
492
|
+
context '#scan' do
|
493
|
+
let(:add) { ->(a, b) { a + b } }
|
494
|
+
let(:mult) { ->(a, b) { a * b; }; }
|
495
|
+
|
496
|
+
it 'scans simple functions over arrays with the supplied accumulator' do
|
497
|
+
expect(R.scan(add, 0, [1, 2, 3, 4])).to eq([0, 1, 3, 6, 10])
|
498
|
+
expect(R.scan(mult, 1, [1, 2, 3, 4])).to eq([1, 1, 2, 6, 24])
|
499
|
+
end
|
500
|
+
|
501
|
+
it 'returns the accumulator for an empty array' do
|
502
|
+
expect(R.scan(add, 0, [])).to eq([0])
|
503
|
+
expect(R.scan(mult, 1, [])).to eq([1])
|
504
|
+
end
|
505
|
+
|
506
|
+
it 'is curried' do
|
507
|
+
add_or_concat = R.scan(add)
|
508
|
+
sum = add_or_concat.call(0)
|
509
|
+
cat = add_or_concat.call('')
|
510
|
+
expect(sum.call([1, 2, 3, 4])).to eq([0, 1, 3, 6, 10])
|
511
|
+
expect(cat.call(['1', '2', '3', '4'])).to eq(['', '1', '12', '123', '1234'])
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
472
515
|
context '#slice' do
|
473
516
|
it 'from docs' do
|
474
517
|
expect(r.slice(1, 3, ['a', 'b', 'c', 'd'])).to eq(['b', 'c'])
|
@@ -551,6 +594,13 @@ describe Ramda::List do
|
|
551
594
|
end
|
552
595
|
end
|
553
596
|
|
597
|
+
context '#unfold' do
|
598
|
+
it 'from docs' do
|
599
|
+
f = ->(n) { n > 50 ? false : [-n, n + 10] }
|
600
|
+
expect(R.unfold(f, 10)).to eq([-10, -20, -30, -40, -50])
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
554
604
|
context '#uniq' do
|
555
605
|
it 'from docs' do
|
556
606
|
expect(r.uniq([1, 1, 2, 1])).to eq([1, 2])
|
data/spec/ramda/logic_spec.rb
CHANGED
@@ -53,6 +53,15 @@ describe Ramda::Logic do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
context '#default_to' do
|
57
|
+
it 'from docs' do
|
58
|
+
default_to42 = R.default_to(42)
|
59
|
+
|
60
|
+
expect(default_to42.call(nil)).to eq(42)
|
61
|
+
expect(default_to42.call('Ramda')).to eq('Ramda')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
56
65
|
context '#if_else' do
|
57
66
|
it 'from docs' do
|
58
67
|
inc_count = R.if_else(
|
data/spec/ramda_spec.rb
CHANGED
@@ -8,6 +8,8 @@ describe Ramda do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# r(:keys_in)
|
11
|
+
# r(:map_accum)
|
12
|
+
# r(:map_accum_right)
|
11
13
|
# r(:math_mod)
|
12
14
|
# r(:to_pairs_in)
|
13
15
|
# r(:values_in)
|
@@ -44,6 +46,7 @@ describe Ramda do
|
|
44
46
|
r(:curry)
|
45
47
|
r(:curry_n)
|
46
48
|
r(:dec)
|
49
|
+
r(:default_to)
|
47
50
|
r(:difference)
|
48
51
|
r(:difference_with)
|
49
52
|
r(:dissoc)
|
@@ -105,6 +108,7 @@ describe Ramda do
|
|
105
108
|
r(:max_by)
|
106
109
|
r(:memoize)
|
107
110
|
r(:merge)
|
111
|
+
r(:merge_all)
|
108
112
|
r(:min)
|
109
113
|
r(:min_by)
|
110
114
|
r(:modulo)
|
@@ -119,6 +123,8 @@ describe Ramda do
|
|
119
123
|
r(:once)
|
120
124
|
r(:or)
|
121
125
|
r(:over)
|
126
|
+
r(:partial)
|
127
|
+
r(:partial_right)
|
122
128
|
r(:partition)
|
123
129
|
r(:path)
|
124
130
|
r(:path_eq)
|
@@ -142,6 +148,7 @@ describe Ramda do
|
|
142
148
|
r(:repeat)
|
143
149
|
r(:replace)
|
144
150
|
r(:reverse)
|
151
|
+
r(:scan)
|
145
152
|
r(:set)
|
146
153
|
r(:slice)
|
147
154
|
r(:sort)
|
@@ -161,6 +168,7 @@ describe Ramda do
|
|
161
168
|
r(:type)
|
162
169
|
r(:unapply)
|
163
170
|
r(:unary)
|
171
|
+
r(:unfold)
|
164
172
|
r(:union)
|
165
173
|
r(:union_with)
|
166
174
|
r(:uniq)
|
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.10.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-07-
|
11
|
+
date: 2017-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby version of Ramda Js library.
|
14
14
|
email:
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/ramda/exception_handler.rb
|
34
34
|
- lib/ramda/function.rb
|
35
35
|
- lib/ramda/internal/curried_method.rb
|
36
|
+
- lib/ramda/internal/dispatchable.rb
|
36
37
|
- lib/ramda/internal/function_with_arity.rb
|
37
38
|
- lib/ramda/internal/functors.rb
|
38
39
|
- lib/ramda/internal/java/__make_curry_proc__.rb
|