Skip to content

Instantly share code, notes, and snippets.

@leonderijke
Created July 3, 2017 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonderijke/18f04f991a5f1945876e285249f5c8ad to your computer and use it in GitHub Desktop.
Save leonderijke/18f04f991a5f1945876e285249f5c8ad to your computer and use it in GitHub Desktop.
EverySet: Set wrapper for using union types in a Set, using `toString` as a hashing function. Can only be used on type that can be stringified.
module EverySet
exposing
( EverySet
, empty
, insert
, isEmpty
, member
, remove
)
import Set exposing (Set)
type alias EverySet =
Set String
hash : a -> String
hash =
toString
empty : EverySet
empty =
Set.empty
isEmpty : EverySet -> Bool
isEmpty everySet =
Set.isEmpty everySet
insert : a -> EverySet -> EverySet
insert item everySet =
Set.insert (hash item) everySet
member : a -> EverySet -> Bool
member item everySet =
Set.member (hash item) everySet
remove : a -> EverySet -> EverySet
remove item everySet =
Set.remove (hash item) everySet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment