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

Miso.Data.Set

Description

Overview

Miso.Data.Set is a Haskell wrapper around the JavaScript Set object. Values of type Set a live in JavaScript memory; all operations run in IO 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.insert 4 s
  b  <- S.member 2 s   -- True
  n  <- S.size s       -- 4
  S.delete 1 s
  pure ()

Operations

See also

Synopsis

Type

data Set key Source #

Instances

Instances details
FromJSVal (Set key) Source # 
Instance details

Defined in Miso.Data.Set

Methods

fromJSVal :: JSVal -> IO (Maybe (Set key)) Source #

fromJSValUnchecked :: JSVal -> IO (Set key) Source #

ToJSVal (Set key) Source # 
Instance details

Defined in Miso.Data.Set

Methods

toJSVal :: Set key -> IO JSVal Source #

Construction

new :: IO (Set key) Source #

Constructs a new JS Set in IO.

fromList Source #

Arguments

:: ToJSVal key 
=> [key]

Elements to populate the new set with

-> IO (Set key) 

Construct a Set from a list of elements.

Operations

insert Source #

Arguments

:: ToJSVal key 
=> key

Element to add

-> Set key

Set to mutate

-> IO () 

Inserts a value into the Set.

member Source #

Arguments

:: ToJSVal key 
=> key

Element to test for membership

-> Set key

Set to query

-> IO Bool 

Checks existence of key in Set, returns t'Bool.

clear :: Set key -> IO () Source #

Empties the Set.

size :: Set key -> IO Int Source #

Return the size of Set.

delete Source #

Arguments

:: ToJSVal key 
=> key

Element to remove

-> Set key

Set to mutate

-> IO Bool 

Removes an element from the Set, returns True if it existed.

union Source #

Arguments

:: ToJSVal key 
=> Set key

First set

-> Set key

Second set

-> IO (Set key) 

The union of two Set

intersection Source #

Arguments

:: ToJSVal key 
=> Set key

First set

-> Set key

Second set

-> IO (Set key) 

The intersection of two Set

difference Source #

Arguments

:: ToJSVal key 
=> Set key

First set

-> Set key

Second set

-> IO (Set key) 

The symmetric difference of two Set

isSubset Source #

Arguments

:: ToJSVal key 
=> Set key

Candidate subset

-> Set key

Potential superset

-> IO Bool 

Checks if one Set is a subset of another Set

isSuperset Source #

Arguments

:: ToJSVal key 
=> Set key

Candidate superset

-> Set key

Potential subset

-> IO Bool 

Checks if one Set is a superset of another Set

isDisjoint Source #

Arguments

:: ToJSVal key 
=> Set key

First set

-> Set key

Second set (disjoint means they share no elements)

-> IO Bool 

Checks if one Set is disjoint from another Set