Ramda Suggest
🐏 🤔
Usage
|
Non-Primitive Inputs
|
Functions as Outputs
This is a library inspired
by suggest.el
and the
constant (valid) feedback I get from people new
to Ramda...
"How do you know what the Ramda function is called?!" - 🤔
"I know what I want to do, but how do I do it?!" - 😫
"Why do the arguments for compose go right to left...?" - 🙃
So this tool will (hopefully) suggest a function in Ramda, you can
use to produce your desired output! For example,
R.sum([1, 2, 3, 4, 5]) = 15
Usage
Install this package in the typical way;
npm install -g ramda-suggest
ramda-suggest true
ramda-suggest 42 41
Non-Primitive Inputs 🐵
Be Warned! ⚠️
The easiest way allow inputs of things other that just primitive
JavaScript data types (i.e. Arrays, Objects, Functions) was to
use eval
.
This will cast Strings that look like Arrays into Arrays! However,
bear in mind that eval
will just evaluate whatever you pass in
in the following formats;
Strings
ramda-suggest foo bar foobar
Objects
ramda-suggest a '{a:1,b:2,c:3}' '{b:2,c3:}'
Note that Objects must be wrapped in single quotes - This is a
limitation of how Node parses command line args.
Arrays
ramda-suggest [1,2,3,4,5] 15
ramda-suggest '[1, 2, 3, 4, 5]' 15
Functions
Functions must be placed inside strings
ramda-suggest '(a, b) => a + b' 0 [1,2,3,4] 10
Function Outputs 🙊
A lot of the time, Ramda will return a function rather than
actual output - You can also test these in the same way you would pass
in functions as arguments! e.g.
ramda-suggest '(a) => a + 5' '() => 10' '() => 15'
Complex output functions
For output functions which take arguments, you should pass them in
using the following format;
("value_1", "value_2") => "return_string"
This will define an output function which when called with the 2
arguments, "value_1"
& "value_2"
(both strings) expects the
return to be "return_string"
.
ramda-suggest '(a) => a + 2' '(a) => a * 2' '(5) => 12'
In the above example, you have two functions which take arguments, and
when composed together basiaclly perform (a) => (a * 2) + 2
, in this
case, we would expect that when we call the returned function with a
value of 5
, we should get 12
out.
This would also work with the following examples
ramda-suggest '(a) => a + 2' '(a) => a * 2' '(10) => 22'
ramda-suggest '(a) => a + 2' '(a) => a * 2' '(100) => 202'
ramda-suggest '(a) => a + 2' '(a) => a * 2' '(2) => 6'
Complexer outputer functionser
You can also use other primtive types as return values from your
output functions, for example
ramda-suggest '(a) => [a, 2]' '(a) => a * 2' '(100) => [200, 2]'
▲ back to top