| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Data.Map
Contents
Description
Overview
Miso.Data.Map is a Haskell wrapper around the JavaScript
Map
object. Values of type live in JavaScript memory; all
operations run in Map k vIO and mutate the underlying JS map in place.
Unlike Map, keys do not require an Ord instance —
any type with a ToJSVal instance can serve as a key, including
JS objects and numeric values that compare by identity.
Use this module when you need to share a key-value structure with a browser
API or a third-party JavaScript library. For pure Haskell processing,
prefer Map.
Import qualified to avoid clashing with Prelude:
import qualified Miso.Data.Map as M
Quick start
import qualified Miso.Data.Map as M example :: IO () example = do m <- M.fromList[("a", 1), ("b", 2 :: Int)] M.insert"c" 3 m v <- M.lookup"b" m -- Just 2 n <- M.sizem -- 3 M.delete"a" m pure ()
Operations
See also
- Miso.Data.Array — mutable JS
Array - Miso.Data.Set — mutable JS
Set - Miso.DSL —
ToJSVal/FromJSValused by key and value types
Synopsis
- data Map key value
- new :: IO (Map key value)
- fromList :: (ToJSVal key, ToJSVal value) => [(key, value)] -> IO (Map key value)
- insert :: (ToJSVal key, ToJSVal value) => key -> value -> Map key value -> IO ()
- lookup :: (ToJSVal key, FromJSVal value) => key -> Map key value -> IO (Maybe value)
- clear :: Map key value -> IO ()
- size :: Map key value -> IO Int
- has :: ToJSVal key => key -> Map key value -> IO Bool
- delete :: ToJSVal key => key -> Map key value -> IO Bool
Type
Instances
Construction
Arguments
| :: (ToJSVal key, ToJSVal value) | |
| => [(key, value)] | Key-value pairs to populate the new map with |
| -> IO (Map key value) |
Construct a Map from a list of key value pairs.
Operations
Arguments
| :: (ToJSVal key, ToJSVal value) | |
| => key | Key to associate the value with |
| -> value | Value to store |
| -> Map key value | Map to mutate |
| -> IO () |
Inserts a value into the Map by key.
Arguments
| :: (ToJSVal key, FromJSVal value) | |
| => key | Key to look up |
| -> Map key value | Map to query |
| -> IO (Maybe value) |
Finds a value in the Map by key.
Checks existence of a value by key, returns t'Bool.