| 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.Set
Contents
Description
Overview
Miso.Data.Set is a Haskell wrapper around the JavaScript
Set
object. Values of type live in JavaScript memory; all
operations run in Set aIO and mutate the underlying JS set in place.
Unlike Set, elements do not require an Ord instance —
any type with a ToJSVal instance can be stored, and equality
is determined by JavaScript's
SameValueZero
algorithm.
Use this module when you need to share a set with a browser API or a
third-party JavaScript library. For pure Haskell processing, prefer
Set.
Import qualified to avoid clashing with Prelude:
import qualified Miso.Data.Set as S
Quick start
import qualified Miso.Data.Set as S example :: IO () example = do s <- S.fromList[1, 2, 3 :: Int] S.insert4 s b <- S.member2 s -- True n <- S.sizes -- 4 S.delete1 s pure ()
Operations
- Construction:
new,fromList - Access:
member,size - Mutation:
insert,delete,clear - Set algebra:
union,intersection,difference,isSubset,isSuperset,isDisjoint
See also
- Miso.Data.Array — mutable JS
Array - Miso.Data.Map — mutable JS
Map - Miso.DSL —
ToJSVal/FromJSValused by element types
Synopsis
- data Set key
- new :: IO (Set key)
- fromList :: ToJSVal key => [key] -> IO (Set key)
- insert :: ToJSVal key => key -> Set key -> IO ()
- member :: ToJSVal key => key -> Set key -> IO Bool
- clear :: Set key -> IO ()
- size :: Set key -> IO Int
- delete :: ToJSVal key => key -> Set key -> IO Bool
- union :: ToJSVal key => Set key -> Set key -> IO (Set key)
- intersection :: ToJSVal key => Set key -> Set key -> IO (Set key)
- difference :: ToJSVal key => Set key -> Set key -> IO (Set key)
- isSubset :: ToJSVal key => Set key -> Set key -> IO Bool
- isSuperset :: ToJSVal key => Set key -> Set key -> IO Bool
- isDisjoint :: ToJSVal key => Set key -> Set key -> IO Bool
Type
Construction
Construct a Set from a list of elements.
Operations
Inserts a value into the Set.
Checks existence of key in Set, returns t'Bool.
The union of two Set
The intersection of two Set
The symmetric difference of two Set