ramda-ruby 0.1.0.alpha
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 +7 -0
- data/.bashrc.docker +2 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +14 -0
- data/.overcommit.yml +73 -0
- data/.pryrc.docker +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +35 -0
- data/CHANGELOG.md +3 -0
- data/Dockerfile +24 -0
- data/Gemfile +23 -0
- data/Gemfile.dev +6 -0
- data/Gemfile.dev.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/ROADMAP.md +14 -0
- data/Rakefile +6 -0
- data/appveyor.yml +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codeclimate.yml +6 -0
- data/docker-compose.override.yml +12 -0
- data/docker-compose.yml +15 -0
- data/docs/FUNCTIONS.md +93 -0
- data/lib/ramda.rb +123 -0
- data/lib/ramda/function.rb +181 -0
- data/lib/ramda/internal/curried_method.rb +16 -0
- data/lib/ramda/internal/function_with_arity.rb +30 -0
- data/lib/ramda/list.rb +372 -0
- data/lib/ramda/logic.rb +58 -0
- data/lib/ramda/math.rb +72 -0
- data/lib/ramda/object.rb +110 -0
- data/lib/ramda/relation.rb +161 -0
- data/lib/ramda/string.rb +49 -0
- data/lib/ramda/version.rb +3 -0
- data/ramda-ruby.gemspec +24 -0
- metadata +80 -0
data/bin/setup
ADDED
data/codeclimate.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
app:
|
2
|
+
volumes:
|
3
|
+
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
|
4
|
+
- ./.bashrc.docker:/root/.bashrc
|
5
|
+
- ./.bash_history.docker:/root/.bash_history
|
6
|
+
# PRY
|
7
|
+
- ./.pry_history.docker:/root/.pry_history
|
8
|
+
- ./.pryrc.docker:/root/.pryrc
|
9
|
+
environment:
|
10
|
+
- CI_REPORTS=/tmp/shippable/testresults
|
11
|
+
- COVERAGE_REPORTS=/tmp/shippable/codecoverage
|
12
|
+
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
app:
|
2
|
+
container_name: rambda_ruby_app
|
3
|
+
build: .
|
4
|
+
dockerfile: Dockerfile
|
5
|
+
volumes:
|
6
|
+
- .:/srv/app
|
7
|
+
- ./config/config.yml.example:/srv/app/config/config.yml
|
8
|
+
volumes_from:
|
9
|
+
- bundle_cache
|
10
|
+
|
11
|
+
bundle_cache:
|
12
|
+
container_name: rambda_ruby_bundle_cache
|
13
|
+
image: busybox
|
14
|
+
volumes:
|
15
|
+
- /bundle_cache
|
data/docs/FUNCTIONS.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
* add
|
2
|
+
* all
|
3
|
+
* all_pass
|
4
|
+
* always
|
5
|
+
* and
|
6
|
+
* any
|
7
|
+
* any_pass
|
8
|
+
* append
|
9
|
+
* clone
|
10
|
+
* comparator
|
11
|
+
* compose
|
12
|
+
* concat
|
13
|
+
* construct
|
14
|
+
* contains
|
15
|
+
* converge
|
16
|
+
* count_by
|
17
|
+
* curry
|
18
|
+
* dec
|
19
|
+
* difference
|
20
|
+
* difference_with
|
21
|
+
* divide
|
22
|
+
* drop
|
23
|
+
* eq_by
|
24
|
+
* eq_props
|
25
|
+
* equals
|
26
|
+
* filter
|
27
|
+
* find
|
28
|
+
* flatten
|
29
|
+
* flip
|
30
|
+
* group_by
|
31
|
+
* gt
|
32
|
+
* gte
|
33
|
+
* head
|
34
|
+
* identity
|
35
|
+
* if_else
|
36
|
+
* inc
|
37
|
+
* index_of
|
38
|
+
* intersection
|
39
|
+
* invoker
|
40
|
+
* is_empty
|
41
|
+
* join
|
42
|
+
* keys
|
43
|
+
* last_index_of
|
44
|
+
* length
|
45
|
+
* lt
|
46
|
+
* lte
|
47
|
+
* map
|
48
|
+
* match
|
49
|
+
* max
|
50
|
+
* memoize
|
51
|
+
* merge
|
52
|
+
* min
|
53
|
+
* multiply
|
54
|
+
* n_ary
|
55
|
+
* not
|
56
|
+
* nth
|
57
|
+
* omit
|
58
|
+
* once
|
59
|
+
* or
|
60
|
+
* pick
|
61
|
+
* pick_all
|
62
|
+
* pipe
|
63
|
+
* pluck
|
64
|
+
* prepend
|
65
|
+
* product
|
66
|
+
* project
|
67
|
+
* prop
|
68
|
+
* prop_eq
|
69
|
+
* props
|
70
|
+
* range
|
71
|
+
* reduce
|
72
|
+
* reduce_right
|
73
|
+
* reject
|
74
|
+
* reverse
|
75
|
+
* sort
|
76
|
+
* sort_by
|
77
|
+
* split
|
78
|
+
* subtract
|
79
|
+
* sum
|
80
|
+
* tail
|
81
|
+
* take
|
82
|
+
* take_while
|
83
|
+
* tap
|
84
|
+
* to_lower
|
85
|
+
* to_upper
|
86
|
+
* union
|
87
|
+
* union_with
|
88
|
+
* uniq
|
89
|
+
* use_with
|
90
|
+
* values
|
91
|
+
* xprod
|
92
|
+
* zip
|
93
|
+
* zip_with
|
data/lib/ramda.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
require 'ramda/version'
|
4
|
+
require 'ramda/function'
|
5
|
+
require 'ramda/list'
|
6
|
+
require 'ramda/logic'
|
7
|
+
require 'ramda/math'
|
8
|
+
require 'ramda/object'
|
9
|
+
require 'ramda/relation'
|
10
|
+
require 'ramda/string'
|
11
|
+
|
12
|
+
# Ramda library implementation, source: http://ramdajs.com/
|
13
|
+
# rubocop:disable Metrics/ModuleLength
|
14
|
+
module Ramda
|
15
|
+
extend SingleForwardable
|
16
|
+
|
17
|
+
def_delegators Ramda::Function,
|
18
|
+
:always,
|
19
|
+
:comparator,
|
20
|
+
:compose,
|
21
|
+
:construct,
|
22
|
+
:converge,
|
23
|
+
:curry,
|
24
|
+
:flip,
|
25
|
+
:identity,
|
26
|
+
:invoker,
|
27
|
+
:memoize,
|
28
|
+
:n_ary,
|
29
|
+
:once,
|
30
|
+
:pipe,
|
31
|
+
:tap,
|
32
|
+
:use_with
|
33
|
+
|
34
|
+
def_delegators Ramda::List,
|
35
|
+
:all,
|
36
|
+
:any,
|
37
|
+
:append,
|
38
|
+
:concat,
|
39
|
+
:contains,
|
40
|
+
:drop,
|
41
|
+
:filter,
|
42
|
+
:find,
|
43
|
+
:flatten,
|
44
|
+
:group_by,
|
45
|
+
:head,
|
46
|
+
:index_of,
|
47
|
+
:join,
|
48
|
+
:last_index_of,
|
49
|
+
:length,
|
50
|
+
:sort,
|
51
|
+
:map,
|
52
|
+
:nth,
|
53
|
+
:pluck,
|
54
|
+
:prepend,
|
55
|
+
:range,
|
56
|
+
:reduce,
|
57
|
+
:reduce_right,
|
58
|
+
:reject,
|
59
|
+
:reverse,
|
60
|
+
:tail,
|
61
|
+
:take,
|
62
|
+
:take_while,
|
63
|
+
:uniq,
|
64
|
+
:xprod,
|
65
|
+
:zip,
|
66
|
+
:zip_with
|
67
|
+
|
68
|
+
def_delegators Ramda::Logic,
|
69
|
+
:all_pass,
|
70
|
+
:and,
|
71
|
+
:any_pass,
|
72
|
+
:if_else,
|
73
|
+
:is_empty,
|
74
|
+
:not,
|
75
|
+
:or
|
76
|
+
|
77
|
+
def_delegators Ramda::Math,
|
78
|
+
:add,
|
79
|
+
:dec,
|
80
|
+
:divide,
|
81
|
+
:inc,
|
82
|
+
:multiply,
|
83
|
+
:product,
|
84
|
+
:subtract,
|
85
|
+
:sum
|
86
|
+
|
87
|
+
def_delegators Ramda::Object,
|
88
|
+
:clone,
|
89
|
+
:eq_props,
|
90
|
+
:keys,
|
91
|
+
:merge,
|
92
|
+
:omit,
|
93
|
+
:pick,
|
94
|
+
:pick_all,
|
95
|
+
:project,
|
96
|
+
:prop,
|
97
|
+
:props,
|
98
|
+
:values
|
99
|
+
|
100
|
+
def_delegators Ramda::Relation,
|
101
|
+
:count_by,
|
102
|
+
:difference,
|
103
|
+
:difference_with,
|
104
|
+
:eq_by,
|
105
|
+
:equals,
|
106
|
+
:gt,
|
107
|
+
:gte,
|
108
|
+
:intersection,
|
109
|
+
:lt,
|
110
|
+
:lte,
|
111
|
+
:max,
|
112
|
+
:min,
|
113
|
+
:prop_eq,
|
114
|
+
:sort_by,
|
115
|
+
:union,
|
116
|
+
:union_with
|
117
|
+
|
118
|
+
def_delegators Ramda::String,
|
119
|
+
:match,
|
120
|
+
:split,
|
121
|
+
:to_lower,
|
122
|
+
:to_upper
|
123
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require_relative 'internal/curried_method'
|
2
|
+
require_relative 'internal/function_with_arity'
|
3
|
+
|
4
|
+
module Ramda
|
5
|
+
# Function functions
|
6
|
+
module Function
|
7
|
+
extend ::Ramda::Internal::CurriedMethod
|
8
|
+
|
9
|
+
curried_method(:always) do |value|
|
10
|
+
-> { value }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Makes a comparator function out of a function that reports whether
|
14
|
+
# the first element is less than the second.
|
15
|
+
#
|
16
|
+
# (a, b -> Boolean) -> (a, b -> Number)
|
17
|
+
#
|
18
|
+
curried_method(:comparator) do |fn|
|
19
|
+
lambda do |a, b|
|
20
|
+
if fn.call(a, b)
|
21
|
+
-1
|
22
|
+
elsif fn.call(b, a)
|
23
|
+
1
|
24
|
+
else
|
25
|
+
0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Performs right-to-left function composition. The rightmost function
|
31
|
+
# may have any arity; the remaining functions must be unary.
|
32
|
+
#
|
33
|
+
# Note: The result of compose is not automatically curried.
|
34
|
+
curried_method(:compose) do |*fns|
|
35
|
+
pipe(*fns.reverse)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Wraps a constructor function inside a curried function that can be called
|
39
|
+
# with the same arguments and returns the same type.
|
40
|
+
#
|
41
|
+
# (* -> {*}) -> (* -> {*})
|
42
|
+
#
|
43
|
+
curried_method(:construct) do |constructor|
|
44
|
+
->(*args) { constructor.new(*args) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Accepts a converging function and a list of branching functions and returns
|
48
|
+
# a new function. When invoked, this new function is applied to some arguments,
|
49
|
+
# each branching function is applied to those same arguments. The results of
|
50
|
+
# each branching function are passed as arguments to the converging function to
|
51
|
+
# produce the return value.
|
52
|
+
#
|
53
|
+
# (x1 -> x2 -> ... -> z) -> [(a -> b -> ... -> x1), ...] -> (a -> b -> ... -> z))]
|
54
|
+
#
|
55
|
+
curried_method(:converge) do |fn, xs, obj|
|
56
|
+
fn.call(*xs.map { |f| f.call(obj) })
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns a curried equivalent of the provided function. The curried function
|
60
|
+
# has two unusual capabilities. First, its arguments needn't be provided
|
61
|
+
# one at a time. If f is a ternary function and g is R.curry(f),
|
62
|
+
# the following are equivalent:
|
63
|
+
#
|
64
|
+
# g(1)(2)(3)
|
65
|
+
# g(1)(2, 3)
|
66
|
+
# g(1, 2)(3)
|
67
|
+
# g(1, 2, 3)
|
68
|
+
|
69
|
+
# (* -> a) -> (* -> a)
|
70
|
+
#
|
71
|
+
curried_method(:curry) do |fn|
|
72
|
+
fn.to_proc.curry
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a new function much like the supplied one, except that the
|
76
|
+
# first two arguments' order is reversed.
|
77
|
+
#
|
78
|
+
# (a -> b -> c -> ... -> z) -> (b -> a -> c -> ... -> z))
|
79
|
+
#
|
80
|
+
curried_method(:flip) do |fn|
|
81
|
+
->(a, b, *args) { fn.curry.call(b, a, *args) }.curry
|
82
|
+
end
|
83
|
+
|
84
|
+
# A function that does nothing but return the parameter supplied to it.
|
85
|
+
# Good as a default or placeholder function.
|
86
|
+
#
|
87
|
+
# a -> a
|
88
|
+
#
|
89
|
+
curried_method(:identity) do |el|
|
90
|
+
el
|
91
|
+
end
|
92
|
+
|
93
|
+
# Turns a named method with a specified arity into a function that can be
|
94
|
+
# called directly supplied with arguments and a target object.
|
95
|
+
# The returned function is curried and accepts arity + 1 parameters where
|
96
|
+
# the final parameter is the target object.
|
97
|
+
#
|
98
|
+
# Number -> String -> (a -> b -> ... -> n -> Object -> *)
|
99
|
+
#
|
100
|
+
curried_method(:invoker) do |arity, method_name|
|
101
|
+
Ramda::Internal::FunctionWithArity.new.call(arity + 1) do |*args, object|
|
102
|
+
object.public_send(method_name, *args)
|
103
|
+
end.curry
|
104
|
+
end
|
105
|
+
|
106
|
+
# Creates a new function that, when invoked, caches the result of calling
|
107
|
+
# fn for a given argument set and returns the result. Subsequent calls to
|
108
|
+
# the memoized fn with the same argument set will not result in an
|
109
|
+
# additional call to fn; instead, the cached result for that set of arguments
|
110
|
+
# will be returned.
|
111
|
+
#
|
112
|
+
# (*... -> a) -> (*... -> a)
|
113
|
+
#
|
114
|
+
curried_method(:memoize) do |fn|
|
115
|
+
memo = {}
|
116
|
+
|
117
|
+
Ramda::Internal::FunctionWithArity.new.call(fn.arity) do |*args|
|
118
|
+
memo[args] = fn.call(*args) unless memo.key?(args)
|
119
|
+
memo[args]
|
120
|
+
end.curry
|
121
|
+
end
|
122
|
+
|
123
|
+
curried_method(:n_ary) do |arity, fn|
|
124
|
+
Ramda::Internal::FunctionWithArity.new.call(arity) do |*args|
|
125
|
+
fn.call(*(args.first(arity) + Array.new(fn.arity - arity, nil)))
|
126
|
+
end.curry
|
127
|
+
end
|
128
|
+
|
129
|
+
# Accepts a function fn and returns a function that guards invocation of fn
|
130
|
+
# such that fn can only ever be called once, no matter how many times the
|
131
|
+
# returned function is invoked. The first value calculated is returned
|
132
|
+
# in subsequent invocations.
|
133
|
+
#
|
134
|
+
# (a... -> b) -> (a... -> b)
|
135
|
+
#
|
136
|
+
curried_method(:once) do |fn|
|
137
|
+
memo = {}
|
138
|
+
|
139
|
+
Ramda::Internal::FunctionWithArity.new.call(fn.arity) do |*args|
|
140
|
+
memo[:result] = fn.call(*args) unless memo.key?(:result)
|
141
|
+
memo[:result]
|
142
|
+
end.curry
|
143
|
+
end
|
144
|
+
|
145
|
+
# Performs left-to-right function composition. The leftmost function may
|
146
|
+
# have any arity; the remaining functions must be unary.
|
147
|
+
# In some libraries this function is named sequence.
|
148
|
+
# Note: The result of pipe is not automatically curried.
|
149
|
+
#
|
150
|
+
# (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z)
|
151
|
+
#
|
152
|
+
curried_method(:pipe) do |*fns|
|
153
|
+
->(*args) { fns.reduce(args) { |memo, fn| [fn.call(*memo)] }.first }
|
154
|
+
end
|
155
|
+
|
156
|
+
# Runs the given function with the supplied object, then returns the object.
|
157
|
+
#
|
158
|
+
# (a -> *) -> a -> a
|
159
|
+
#
|
160
|
+
curried_method(:tap) do |fn, x|
|
161
|
+
fn.call(x)
|
162
|
+
x
|
163
|
+
end
|
164
|
+
|
165
|
+
# Accepts a function fn and a list of transformer functions and returns
|
166
|
+
# a new curried function. When the new function is invoked, it calls the
|
167
|
+
# function fn with parameters consisting of the result of calling each
|
168
|
+
# supplied handler on successive arguments to the new function.
|
169
|
+
#
|
170
|
+
# (x1 -> x2 -> ... -> z) -> [(a -> b -> ... -> x1), ...] -> (a -> b -> ... -> z)
|
171
|
+
#
|
172
|
+
curried_method(:use_with) do |fn, fns|
|
173
|
+
Ramda::Internal::FunctionWithArity.new.call(fns.count) do |*args|
|
174
|
+
modified_args = args.each_with_index.map do |arg, index|
|
175
|
+
fns[index].call(arg)
|
176
|
+
end
|
177
|
+
fn.call(*modified_args)
|
178
|
+
end.curry
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|