Object
deleteAt
Delete a key and value from an object.
Example
RESCRIPTlet t1 = {"foo": "bar", "bar": "foo"} // does not mutate
let t2 = t1->Object.deleteAt("bar") // => {"foo": "bar"}
has
Test whether or not a key exists in an object.
Example
RESCRIPTlet point = {"x": 1, "y": 2}
{"a": 1}->Object.has("a") // => true
{"a": 1}->Object.has("b") // => false
{"a": 1}->Object.has("toString") // => false
isEmpty
Test whether an Object is empty.
Example
RESCRIPT%raw("{}")->Object.isEmpty // => true
{"foo": "bar"}->Object.isEmpty // => false
filter
Given a Predicate, it produces a new Object keeping only the entries with a value that satisfies the provided predicate.
Example
RESCRIPT{"one": 1, "two": 2}->Object.filter(n => n < 2) // => {"one": 1}
get
Gets the value of a property by name. Returns None
if the property does not exist or has the value undefined
. Otherwise returns Some
, including if the value is null
.
Example
RESCRIPT{"a": 1}->Object.get("a") // => Some(1)
{"a": 1}->Object.get("b") // => None
keysToArray
Returns an array of an object's own enumerable string-keyed property names. See ECMAScript Language Specification or Object.keys on MDN.
Example
RESCRIPT{"a": 1, "b": 2}->Object.keysToArray // => ["a", "b"]
{"a": None}->Object.keysToArray // => ["a"]
Object.empty()->Object.keysToArray // => []
map
Map an object passing the values to the iterating function.
Example
RESCRIPTlet t1 = {"a": 1, "b": 2} // does not mutate
let t2 = t1->Object.map(n => n + 10) // => {"a": 11, "b": 12}
merge
Merges two objects together without mutating either source object.
Example
RESCRIPTlet t1 = {"foo": "bar"} // does not mutate
let t2 = {"bar": "foo"} // does not mutate
let t3 = Object.merge(t1, t2) // => {"foo": "bar", "bar": "foo"}
set
Set a key to a new value on an object. Returns an updated copy of the object and does not mutate the input object.
Example
RESCRIPTlet t1 = {"foo": "bar"} // this does not mutate
let t2 = t1->Object.set("foo", "new") // => { "foo": "new" }