Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Ramda have isString?

Background

I am trying to use ramda and I need a pure function that lets me know if a given input is a string or not, much like lodash _.isString.

Question

After searching everywhere I couldn't find anything in Ramda for this. So I wonder, is there a way, using any of Ramda's existing functions, that I can create a isString function?

I find this horribly limiting and is it is not possible i might just use lodash in the end :S

like image 453
Flame_Phoenix Avatar asked Dec 13 '17 16:12

Flame_Phoenix


People also ask

What is compose in ramda?

compose FunctionPerforms right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.

What is JavaScript ramda?

Ramda is a practical functional library for JavaScript programmers. The library focuses on immutability and side-effect free functions. Ramda functions are also automatically curried, which allows to build up new functions from old ones simply by not supplying the final parameters.


1 Answers

Rather than have isString, isObject, isArray, isFunction, etc, Ramda simply provides is, which you can use to create any of these you like:

const isString = R.is(String)
const isRectangle = R.is(Rectangle)

isString('foo') //=> true
isString(42) //=> false

isRectangle(new Rectangle(3, 5)) //=> true
isRectangle(new Square(7)) //=> true (if Rectangle is in the prototype chain of Square)
isRectangle(new Triangle(3, 4, 5)) //=> false

And you don't have to create the intermediate function. You can just use it as is:

R.is(String, 'foo') //=> true
R.is(String, {a: 'foo'}) //=> false
like image 62
Scott Sauyet Avatar answered Oct 13 '22 22:10

Scott Sauyet