stoeffel/set-extra/1.2.1

NOTE: this package is not compatible with Elm 0.19.1

Set.Extra

Convenience functions for working with Set.

concatMap : (comparable -> Set comparable2) -> Set comparable -> Set comparable2

Map a given function onto a set and union the resulting set.

neighbors :: (Int, Int) -> Set (Int, Int)
neighbors (x, y) =
    Set.fromList
      [ (x - 1, y - 1), (x, y - 1), (x + 1, y - 1)
      , (x - 1, y),                 (x + 1, y)
      , (x - 1, y + 1), (x, y + 1), (x + 1, y + 1)
      ]
Set.Extra.concatMap neighbors setOfPoints
(comparable -> Maybe comparable2)
-> Set comparable
-> Set comparable2

Apply a function that may succeed to all values in the set, but only keep the successes.

Set.fromList ["1", "2", "a", "3"]
    |> Set.Extra.filterMap (String.toFloat >> Result.toMaybe)
--> Set.fromList [1, 2, 3]
subset : Set comparable -> Set comparable -> Bool

Check if a Set is a subset of another Set.

Set.Extra.subset (Set.fromList [1,2,3]) (Set.fromList [1,2,3,4,5])
--> True
toggle : comparable -> Set comparable -> Set comparable

If the set does not contain the element, add it. If it does contain the element, remove it.

Set.Extra.toggle 1 (Set.fromList [1,2,3]) --> Set.fromList [2, 3]


Set.Extra.toggle 1 (Set.fromList [2,3])   --> Set.fromList [1, 2, 3]
-- This module is used in the examples
import Set