Ramda’s R.is() answers a yes/no question: is this value an instance of that constructor? You pass a constructor, then a value. You get back a Boolean. The check walks the inheritance chain, so an array is both Array and Object. It is not the same as JavaScript’s instanceof: R.is(Number, 1) is true while (1 instanceof Number) is false, because Ramda also compares val.constructor. Primitives still are not Object: R.is(Object, 's') is false, while boxed new String('') is Object. A typical idea is val != null && (val.constructor === Ctor || val instanceof Ctor), so null and undefined are false for every constructor. Need a string tag instead of a Boolean? That is Type cousin R.type. Need null or undefined as a Boolean? That is Type cousin R.isNil. Need a property that matches a constructor? That is Type cousin R.propIs. Need empty vs filled? That is R.isEmpty or R.empty. Lodash has no single _.is(ctor); it ships _.isString, _.isNumber, _.isObject (and _.isObject(1) is false, _.isObject([]) is true — similar pitfalls).
The official sample is the whole idea. {} is Object. 1 is Number, not Object. 's' is String, not Object. Boxed new String('') is both String and Object. Previous helper is R.unionWith. Next is R.isNil.
Syntax
Call R.is. Start with this line.
Ramda
R.is(ctor, val)
Call
What it does
R.is(ctor, val)
Primary signature.
R.is(...)
Call the type helper.
Prefer import { is } from "ramda" when you want a named import.
Library declarations
Ramda
R.is(ctor, val)
Parameters
Parameter
Description
ctor
Required. Constructor. A constructor function, such as Object, Number, String, Array, or a user class.
val
Required. Any. The value to test. Primitives, objects, functions, null, and undefined are allowed.
Return Value
Return Value
Description
Boolean
true when val is an instance of ctor (including the inheritance chain). null and undefined are always false.
Ramda Examples
📚 Getting Started
The official Ramda samples in one snippet, then the same primitive cases next to native instanceof.
Example 1 — Official Samples
Every docs line in one list. Constructor first, value last, Boolean back.
That is the docs sample from ramdajs.com. A plain object is Object. A primitive number is Number, not Object. A primitive string is String, not Object. A boxed string is both String and Object. Example 2 shows why that Number check beats instanceof.
Example 2 — vs instanceof
1 instanceof Number is false. R.is(Number, 1) is true. The same split happens for 's' vs String. Ramda uses .constructor as well as instanceof.
Two columns, same values. Native instanceof only looks at the prototype chain, so primitives fail. Ramda also compares val.constructor === Ctor. That is the whole teaching gap. Example 3 then splits boxed wrappers from primitives on Object.
📈 Practical Patterns
Boxed String vs primitive string, arrays and classes on the Object chain, then a curried map leftover.
Example 3 — Boxed String vs Primitive
new String('') is both String and Object. Primitive 's' is String, not Object. Boxed wrappers sit on the Object chain; primitives do not.
Ramda
R.is(String, new String(''));
//=> true
R.is(Object, new String(''));
//=> true
R.is(String, 's');
//=> true
R.is(Object, 's');
//=> false
Official docs already show this pair. Treat boxed wrappers as objects. Treat primitive strings as String only. The same pattern holds for new Number(1) vs 1 if you ever box a number.
Example 4 — Inheritance, Classes, Object.create
Arrays and user classes walk the Object chain. Object.create({}) is Object. Object.create(null) has no Object prototype, so it is not Object. null and undefined are false for every constructor.
Inheritance is the point of instanceof inside Ramda. Object.create({}) (or Object.create(Object.prototype)) still sits on Object. Object.create(null) does not. The val != null short-circuit keeps missing values false for every constructor.
Example 5 — Curried leftover with R.map
Arity 2, data last: fill the constructor, keep a predicate. Map it over a mixed list. NaN is still a Number.
R.is(Number) waits for the value. '1' is a string. NaN.constructor is still Number, so the leftover says true. A plain object is not a Number. Name leftovers like isNum and reuse them in R.filter or R.pipe.
Compatibility
Browser Support
R.is() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.3.0+ · Any JS runtime
Ramda.js R.is()
Load Ramda 0.3.0 or later via CDN or npm, then call R.is with a constructor and a value. No extra browser API is required.
100%With Ramda 0.3.0+
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
R.is()Universal
Bottom line: Safe in any project that includes Ramda 0.3.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].
Frequently Asked Questions
R.is(ctor, val) is true when val is an instance of the supplied constructor, including the inheritance chain. Type: (* → {*}) → a → Boolean. Parameters: ctor (a constructor) and val (the value to test). Returns Boolean. Arity 2, curried, data last. Added in v0.3.0.
R.is(Object, {}) is true. R.is(Number, 1) is true. R.is(Object, 1) is false. R.is(String, 's') is true. R.is(String, new String('')) is true. R.is(Object, new String('')) is true. R.is(Object, 's') is false. R.is(Number, {}) is false.
R.is(Number, 1) is true; (1 instanceof Number) is false. Ramda treats primitives via .constructor as well as instanceof, so a primitive matches its boxed constructor. Primitives are still not Object: R.is(Object, 's') is false, while boxed new String('') is Object.
R.type returns a STRING tag such as "Number". R.is returns a Boolean for a constructor you pass in. Use type when you want a native kind name; use is when you already know the constructor and need yes or no.
R.is(String, 's') is true and R.is(Object, 's') is false. R.is(String, new String('')) is true and R.is(Object, new String('')) is true. Boxed wrappers sit on the Object inheritance chain; primitive strings do not.
No. R.is is a stable Ramda Type helper from v0.3.0. It is not deprecated, experimental, or non-standard.