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
.
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
compose FunctionPerforms right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With