Module

Foreign.Object

Package
purescript-foreign-object
Repository
purescript/purescript-foreign-object

This module defines a type of native homogeneous Javascript Objects.

To maximize performance, Javascript objects are not wrapped, and some native code is used even when it's not necessary.

#Object Source

data Object :: Type -> Type

Object a represents a homogeneous JS Object with values of type a.

Instances

#empty Source

empty :: forall a. Object a

An empty map

#isEmpty Source

isEmpty :: forall a. Object a -> Boolean

Test whether a map is empty

#size Source

size :: forall a. Object a -> Int

Calculate the number of key/value pairs in a map

#singleton Source

singleton :: forall a. String -> a -> Object a

Create an Object a with one key/value pair

#insert Source

insert :: forall a. String -> a -> Object a -> Object a

Insert or replace a key/value pair in a map

#lookup Source

lookup :: forall a. String -> Object a -> Maybe a

Lookup the value for a key in a map

#toUnfoldable Source

toUnfoldable :: forall a f. Unfoldable f => Object a -> f (Tuple String a)

Unfolds a map into a list of key/value pairs

#toAscUnfoldable Source

toAscUnfoldable :: forall a f. Unfoldable f => Object a -> f (Tuple String a)

Unfolds a map into a list of key/value pairs which is guaranteed to be sorted by key

#fromFoldable Source

fromFoldable :: forall a f. Foldable f => f (Tuple String a) -> Object a

Create an Object a from a foldable collection of key/value pairs

#fromFoldableWith Source

fromFoldableWith :: forall a f. Foldable f => (a -> a -> a) -> f (Tuple String a) -> Object a

Create an Object a from a foldable collection of key/value pairs, using the specified function to combine values for duplicate keys.

#fromHomogeneous Source

fromHomogeneous :: forall a r. Homogeneous r a => Record r -> Object a

Create an Object a from a homogeneous record, i.e. all of the record fields are of the same type.

#delete Source

delete :: forall a. String -> Object a -> Object a

Delete a key and value from a map

#pop Source

pop :: forall a. String -> Object a -> Maybe (Tuple a (Object a))

Delete a key and value from a map, returning the value as well as the subsequent map

#member Source

member :: forall a. String -> Object a -> Boolean

Test whether a String appears as a key in a map

#alter Source

alter :: forall a. (Maybe a -> Maybe a) -> String -> Object a -> Object a

Insert, remove or update a value for a key in a map

#update Source

update :: forall a. (a -> Maybe a) -> String -> Object a -> Object a

Remove or update a value for a key in a map

#mapWithKey Source

mapWithKey :: forall b a. (String -> a -> b) -> Object a -> Object b

Apply a function of two arguments to each key/value pair, producing a new map

#filterWithKey Source

filterWithKey :: forall a. (String -> a -> Boolean) -> Object a -> Object a

Filter out those key/value pairs of a map for which a predicate fails to hold.

#filterKeys Source

filterKeys :: (String -> Boolean) -> Object ~> Object

Filter out those key/value pairs of a map for which a predicate on the key fails to hold.

#filter Source

filter :: forall a. (a -> Boolean) -> Object a -> Object a

Filter out those key/value pairs of a map for which a predicate on the value fails to hold.

#keys Source

keys :: forall a. Object a -> Array String

Get an array of the keys in a map

#values Source

values :: forall a. Object a -> Array a

Get a list of the values in a map

#union Source

union :: forall a. Object a -> Object a -> Object a

Compute the union of two maps, preferring the first map in the case of duplicate keys.

#unions Source

unions :: forall a f. Foldable f => f (Object a) -> Object a

Compute the union of a collection of maps

#isSubmap Source

isSubmap :: forall a. Eq a => Object a -> Object a -> Boolean

Test whether one map contains all of the keys and values contained in another map

#fold Source

fold :: forall z a. (z -> String -> a -> z) -> z -> Object a -> z

Fold the keys and values of an object

#foldMap Source

foldMap :: forall m a. Monoid m => (String -> a -> m) -> Object a -> m

Fold the keys and values of an object, accumulating values using some Monoid.

#foldM Source

foldM :: forall z m a. Monad m => (z -> String -> a -> m z) -> z -> Object a -> m z

Fold the keys and values of an object, accumulating values and effects in some Monad.

#foldMaybe Source

foldMaybe :: forall z a. (z -> String -> a -> Maybe z) -> z -> Object a -> z

Fold the keys and values of a map.

This function allows the folding function to terminate the fold early, using Maybe.

#all Source

all :: forall a. (String -> a -> Boolean) -> Object a -> Boolean

Test whether all key/value pairs in a Object satisfy a predicate.

#thawST Source

thawST :: forall r a. Object a -> ST r (STObject r a)

Convert an immutable Object into a mutable Object

#freezeST Source

freezeST :: forall r a. STObject r a -> ST r (Object a)

Convert a mutable Object into an immutable Object

#runST Source

runST :: forall a. (forall r. ST r (STObject r a)) -> Object a

Freeze a mutable Object, creating an immutable Object. Use this function as you would use ST.run to freeze a mutable reference.

The rank-2 type prevents the Object from escaping the scope of runST.

#toArrayWithKey Source

toArrayWithKey :: forall b a. (String -> a -> b) -> Object a -> Array b