miso
Copyright(C) 2016-2025 David M. Johnson (@dmjio)
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Data.Array

Description

Mutable Array data structure in IO.

A JavaScript Array. This is a convenience for manipulating JavaScript data structures from Haskell.

We recommend using this module qualified.

import qualified Miso.Data.Array as M
Synopsis

Type

data Array value Source #

Instances

Instances details
FromJSVal (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

fromJSVal :: JSVal -> IO (Maybe (Array value)) Source #

fromJSValUnchecked :: JSVal -> IO (Array value) Source #

ToJSVal (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

toJSVal :: Array value -> IO JSVal Source #

ToObject (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

toObject :: Array value -> IO Object Source #

Construction

new :: IO (Array value) Source #

Constructs a new JS Array in IO.

fromList :: ToJSVal value => [value] -> IO (Array value) Source #

Construct a Array from a list of value value pairs.

Deconstruction

toList :: FromJSVal value => Array value -> IO [value] Source #

Converts an Array to a list.

Operations

insert :: ToJSVal value => Int -> value -> Array value -> IO () Source #

Inserts a value into the Array by value.

push :: ToJSVal value => value -> Array value -> IO () Source #

Inserts a value into the Array by value.

member :: ToJSVal value => value -> Array value -> IO Bool Source #

Checks existence of value in Array, returns t'Bool.

size :: Array value -> IO Int Source #

Return the size of Array.

splice :: ToJSVal value => Int -> Int -> [value] -> Array value -> IO (Array value) Source #

Splices an array. See splice.

singleton :: ToJSVal a => a -> IO (Array a) Source #

Creates a new Array with a single element.

pop :: FromJSVal a => Array a -> IO (Maybe a) Source #

Removes the last element from an array and returns it.

Returns Nothing if the Array is empty.

shift :: FromJSVal a => Array a -> IO (Maybe a) Source #

Removes the first element from an array and returns it.

unshift :: ToJSVal a => a -> Array a -> IO Int Source #

Adds one or more elements to the beginning of an array.

null :: Array value -> IO Bool Source #

Return the null of Array.

lookup :: FromJSVal value => Int -> Array value -> IO (Maybe value) Source #

Look up a value in the array by key.

(!?) :: FromJSVal value => Int -> Array value -> IO value Source #

Look up a value in the array by key.

reverse :: Array a -> IO () Source #

Reverses an array in-place.