ramda-ruby 0.8.0 → 0.8.1
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 +5 -0
- data/README.md +75 -6
- data/ROADMAP.md +125 -16
- data/lib/ramda.rb +9 -0
- data/lib/ramda/exception_handler.rb +22 -0
- data/lib/ramda/internal/curried_method.rb +1 -1
- data/lib/ramda/list.rb +2 -2
- data/lib/ramda/object.rb +1 -1
- data/lib/ramda/relation.rb +1 -1
- data/lib/ramda/version.rb +1 -1
- data/spec/ramda/internal/curried_method_spec.rb +17 -5
- data/spec/ramda/list_spec.rb +7 -1
- 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: 551c4cf30d89de74593b3d778aa686c240a80daf
|
4
|
+
data.tar.gz: cf3ae825a6eec5dd22feecdf318cd49578b79416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e911adf71d38c300aa2852872b11d35c0bc03fb3f7d7700d8f1f7171b4c0ba18e150cf4189baf683a80bab43c3d497f46f403c52fbaa63609978608ab1ae6451
|
7
|
+
data.tar.gz: b5f58b29149340e02badd0ab0804e797550699ccb7df3c6cd1b00344906b1c3b69f95ba703ac1e1bacae02e07ed378b91d6507277d393a93b59ab007e0bc0007
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,6 +12,12 @@ This is a ruby version of [Ramda Js](http://ramdajs.com) library.
|
|
12
12
|
[](https://gemnasium.com/lazebny/ramda-ruby)
|
13
13
|
[](http://opensource.org/licenses/MIT)
|
14
14
|
|
15
|
+
Problems
|
16
|
+
------------
|
17
|
+
|
18
|
+
This gem is stable but i think it isn't production ready - benchmarks
|
19
|
+
are showing a huge performance loss comparing to the plain ruby.
|
20
|
+
|
15
21
|
|
16
22
|
Installation
|
17
23
|
------------
|
@@ -36,7 +42,9 @@ And then require:
|
|
36
42
|
require 'ramda'
|
37
43
|
```
|
38
44
|
|
39
|
-
|
45
|
+
|
46
|
+
Documentation
|
47
|
+
-------------
|
40
48
|
|
41
49
|
Currently the gem doesn't have own documentation but it tries to follow specification from [Ramda Js](http://ramdajs.com/docs/)
|
42
50
|
|
@@ -47,10 +55,13 @@ You could use [Ramda Js](http://ramdajs.com/docs/) as a source of documentation.
|
|
47
55
|
|
48
56
|
Ruby scpecific examples can be found in [tests](spec/ramda).
|
49
57
|
|
50
|
-
|
58
|
+
|
59
|
+
Usage
|
60
|
+
-------------
|
51
61
|
|
52
62
|
Pointless Style:
|
53
63
|
|
64
|
+
|
54
65
|
```ruby
|
55
66
|
|
56
67
|
R = Ramda
|
@@ -75,18 +86,76 @@ Placeholder:
|
|
75
86
|
|
76
87
|
```
|
77
88
|
|
78
|
-
|
89
|
+
Change Exceptions Handler:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
|
93
|
+
# To use a default 'with_narrow' handler:
|
94
|
+
Ramda.exception_handler = nil
|
95
|
+
# the same as:
|
96
|
+
Ramda.exception_handler = -> Ramda::ExceptionHandler.method(:with_narrow)
|
97
|
+
|
98
|
+
# Set a custom handler:
|
99
|
+
Ramda.exception_handler = -> (e, _method_name) { raise e, e.exception, e.backtrace }
|
100
|
+
# the same as:
|
101
|
+
Ramda.exception_handler = -> Ramda::ExceptionHandler.method(:default)
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
Benchmarks
|
107
|
+
-------------
|
108
|
+
|
109
|
+
* [Function](bench_results/FUNCTION.md)
|
110
|
+
* [List](bench_results/LIST.md)
|
111
|
+
* [Logic](bench_results/LOGIC.md)
|
112
|
+
* [Math](bench_results/MATH.md)
|
113
|
+
* [Object](bench_results/OBJECT.md)
|
114
|
+
* [Relation](bench_results/RELATION.md)
|
115
|
+
* [String](bench_results/STRING.md)
|
116
|
+
* [Type](bench_results/TYPE.md)
|
117
|
+
|
118
|
+
Send all results to STDOUT
|
119
|
+
|
120
|
+
```sh
|
121
|
+
bundle exec rake ramda:run_benchmark
|
122
|
+
```
|
123
|
+
|
124
|
+
Send one function type results to STDOUT
|
125
|
+
|
126
|
+
```sh
|
127
|
+
bundle exec rake ramda:run_benchmark[bench/list/*]
|
128
|
+
```
|
129
|
+
|
130
|
+
Update all files in [bench_results](bench_results)
|
131
|
+
|
132
|
+
```sh
|
133
|
+
bundle exec rake ramda:run_benchmark_to_file
|
134
|
+
```
|
135
|
+
|
136
|
+
Update one type of function in [bench_results](bench_results)
|
137
|
+
|
138
|
+
```sh
|
139
|
+
bundle exec rake ramda:run_benchmark_to_file[bench/list/*]
|
140
|
+
```
|
141
|
+
|
142
|
+
|
143
|
+
Development
|
144
|
+
--------------
|
79
145
|
|
80
146
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
81
147
|
|
82
148
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
83
149
|
|
84
|
-
## Contributing
|
85
150
|
|
86
|
-
|
151
|
+
Contributing
|
152
|
+
--------------
|
153
|
+
|
154
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lazebny/ramda-ruby.
|
87
155
|
|
88
156
|
|
89
|
-
|
157
|
+
License
|
158
|
+
--------------
|
90
159
|
|
91
160
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
92
161
|
|
data/ROADMAP.md
CHANGED
@@ -1,25 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* Find out suitable documentation format
|
4
|
-
|
5
|
-
### release 0.8.0
|
6
|
-
|
7
|
-
### release 0.9.0
|
8
|
-
|
9
|
-
* all_pass
|
10
|
-
* any_pass
|
1
|
+
Release 0.9.0
|
2
|
+
---------------
|
11
3
|
* call
|
12
|
-
* dec
|
13
4
|
* drop_while
|
14
5
|
* evolve
|
15
|
-
* inc
|
16
6
|
* init
|
17
7
|
* insert_all
|
18
8
|
* invert
|
19
9
|
* invert_obj
|
20
|
-
* is_nil
|
21
10
|
* map_obj_indexed
|
22
|
-
* negate
|
23
11
|
* nth_arg
|
24
|
-
|
25
|
-
|
12
|
+
|
13
|
+
Release 0.10.0
|
14
|
+
---------------
|
15
|
+
* compose_p
|
16
|
+
* default_to
|
17
|
+
* map_accum
|
18
|
+
* map_accum_right
|
19
|
+
* merge_all
|
20
|
+
* partial
|
21
|
+
* partial_right
|
22
|
+
* pipe_p
|
23
|
+
* scan
|
24
|
+
* unfold
|
25
|
+
|
26
|
+
Release 0.11.0
|
27
|
+
---------------
|
28
|
+
* dissoc_path
|
29
|
+
|
30
|
+
Release 0.12.0
|
31
|
+
---------------
|
32
|
+
* apperture
|
33
|
+
* both
|
34
|
+
* either
|
35
|
+
* into
|
36
|
+
* none
|
37
|
+
* test
|
38
|
+
* transduce
|
39
|
+
|
40
|
+
Release 0.13.0
|
41
|
+
---------------
|
42
|
+
|
43
|
+
Release 0.14.0
|
44
|
+
---------------
|
45
|
+
* adjust
|
46
|
+
* drop_repeats
|
47
|
+
* drop_repeats_with
|
48
|
+
* intersperse
|
49
|
+
* mean
|
50
|
+
* median
|
51
|
+
* to_string
|
52
|
+
* uncurry_n
|
53
|
+
* where_eq
|
54
|
+
|
55
|
+
Releaes 0.15.0
|
56
|
+
---------------
|
57
|
+
* add_index
|
58
|
+
* identical
|
59
|
+
* reduced
|
60
|
+
|
61
|
+
Release 0.16.0
|
62
|
+
---------------
|
63
|
+
* compose_k
|
64
|
+
* drop_last
|
65
|
+
* drop_last_while
|
66
|
+
* pipe_k
|
67
|
+
* prop_is
|
68
|
+
* prop_satisfies
|
69
|
+
* split_every
|
70
|
+
* take_last
|
71
|
+
* take_last_while
|
72
|
+
* uniq_by
|
73
|
+
|
74
|
+
Release 0.17.0
|
75
|
+
---------------
|
76
|
+
|
77
|
+
Release 0.18.0
|
78
|
+
---------------
|
79
|
+
* eq_by
|
80
|
+
* obj_of
|
81
|
+
* pair
|
82
|
+
* path_or
|
83
|
+
* unless
|
84
|
+
* when
|
85
|
+
|
86
|
+
Release 0.19.0
|
87
|
+
---------------
|
88
|
+
* index_by
|
89
|
+
* merge_with
|
90
|
+
* merge_with_key
|
91
|
+
* path_satistfies
|
92
|
+
* sequence
|
93
|
+
* split_at
|
94
|
+
* split_when
|
95
|
+
* symmetric_difference
|
96
|
+
* symmetric_difference_with
|
97
|
+
* transpose
|
98
|
+
* traverse
|
99
|
+
* without
|
100
|
+
|
101
|
+
Release 0.20.0
|
102
|
+
---------------
|
103
|
+
* apply_spec
|
104
|
+
* clamp
|
105
|
+
* reduce_by
|
106
|
+
* try_catch
|
107
|
+
* until
|
108
|
+
|
109
|
+
Release 0.21.0
|
110
|
+
---------------
|
111
|
+
* group_with
|
112
|
+
|
113
|
+
Release 0.22.0
|
114
|
+
---------------
|
115
|
+
* reduce_while
|
116
|
+
|
117
|
+
Release 0.23.0
|
118
|
+
---------------
|
119
|
+
* ascend
|
120
|
+
* descend
|
121
|
+
* for_each_obj_indexed
|
122
|
+
* sort_with
|
123
|
+
|
124
|
+
Release 0.24.0
|
125
|
+
---------------
|
126
|
+
* ends_with
|
127
|
+
* inner_join
|
128
|
+
* memoize_with
|
129
|
+
* merge_deep_left
|
130
|
+
* merge_deep_right
|
131
|
+
* merge_deep_with
|
132
|
+
* merge_deep_with_key
|
133
|
+
* o
|
134
|
+
* starts_with
|
data/lib/ramda.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
require 'ramda/version'
|
4
|
+
require 'ramda/exception_handler'
|
4
5
|
require 'ramda/function'
|
5
6
|
require 'ramda/list'
|
6
7
|
require 'ramda/logic'
|
@@ -189,4 +190,12 @@ module Ramda
|
|
189
190
|
:is,
|
190
191
|
:is_nil,
|
191
192
|
:type
|
193
|
+
|
194
|
+
def self.exception_handler=(handler)
|
195
|
+
@exception_handler = handler
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.exception_handler
|
199
|
+
@exception_handler ||= ::Ramda::ExceptionHandler.method(:with_narrow)
|
200
|
+
end
|
192
201
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ramda
|
2
|
+
# Exception Handlers
|
3
|
+
module ExceptionHandler
|
4
|
+
# This handler is useful for debug.
|
5
|
+
#
|
6
|
+
# Output example:
|
7
|
+
# compose -> map -> add -> ... original message ... with backtrace:
|
8
|
+
# ...
|
9
|
+
# original backtrace
|
10
|
+
# ...
|
11
|
+
#
|
12
|
+
def self.with_narrow(e, method_name)
|
13
|
+
raise e, [method_name, e.exception].join(' -> '), e.backtrace
|
14
|
+
end
|
15
|
+
|
16
|
+
# This handler follows a standard behavior.
|
17
|
+
#
|
18
|
+
def self.default(e, *)
|
19
|
+
raise e, e.exception, e.backtrace
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/ramda/list.rb
CHANGED
@@ -34,7 +34,7 @@ module Ramda
|
|
34
34
|
# a -> [a] -> [a]
|
35
35
|
#
|
36
36
|
curried_method(:append) do |x, xs|
|
37
|
-
xs
|
37
|
+
xs + [x]
|
38
38
|
end
|
39
39
|
|
40
40
|
# chain maps a function over a list and concatenates the results. chain is
|
@@ -288,7 +288,7 @@ module Ramda
|
|
288
288
|
when ::String
|
289
289
|
xs[index] || ''
|
290
290
|
when ::Array, ::Hash
|
291
|
-
xs
|
291
|
+
xs[index]
|
292
292
|
else
|
293
293
|
type_error(xs, :nth)
|
294
294
|
end
|
data/lib/ramda/object.rb
CHANGED
@@ -209,7 +209,7 @@ module Ramda
|
|
209
209
|
# Idx = String | Int
|
210
210
|
#
|
211
211
|
curried_method(:path) do |keys, obj|
|
212
|
-
keys.reduce(obj) { |acc, key| acc.respond_to?(:fetch) ? acc
|
212
|
+
keys.reduce(obj) { |acc, key| acc.respond_to?(:fetch) ? acc[key] : nil }
|
213
213
|
end
|
214
214
|
|
215
215
|
# Returns a partial copy of an object containing only the keys specified.
|
data/lib/ramda/relation.rb
CHANGED
data/lib/ramda/version.rb
CHANGED
@@ -31,13 +31,25 @@ describe Ramda::Internal::CurriedMethod do
|
|
31
31
|
# expect(instance.g(R.__, 2).call(R.__, 3).call(1)).to eq(6)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
a
|
34
|
+
context 'exception handler' do
|
35
|
+
before do
|
36
|
+
instance.curried_method(:g) do |a, b, c|
|
37
|
+
a + b + c
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
Ramda.exception_handler = nil
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
|
-
.to raise_error(/g -> String can't be coerced/)
|
45
|
+
it 'default behavior' do
|
46
|
+
expect { instance.g(1, '', 2) }.to raise_error(/g -> String can't be coerced/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'exception_handler=' do
|
50
|
+
Ramda.exception_handler = ->(*) { raise 'ABC some exception' }
|
51
|
+
expect { instance.g(1, '', 2) }.to raise_error(/ABC some exception/)
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
data/spec/ramda/list_spec.rb
CHANGED
@@ -40,7 +40,13 @@ describe Ramda::List do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'is curried' do
|
43
|
-
expect(
|
43
|
+
expect(r.append(1).call([4, 3, 2])).to eq([4, 3, 2, 1])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'do not mutate array' do
|
47
|
+
a = [1, 2]
|
48
|
+
expect(r.append(100, a)).to eq([1, 2, 100])
|
49
|
+
expect(a).to eq([1, 2])
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
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.8.
|
4
|
+
version: 0.8.1
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby version of Ramda Js library.
|
14
14
|
email:
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- ROADMAP.md
|
29
29
|
- docs/FUNCTIONS.md
|
30
30
|
- lib/ramda.rb
|
31
|
+
- lib/ramda/exception_handler.rb
|
31
32
|
- lib/ramda/function.rb
|
32
33
|
- lib/ramda/internal/curried_method.rb
|
33
34
|
- lib/ramda/internal/function_with_arity.rb
|