packages feed

papa-0.7.0: src/Papa/UnorderedContainers/Data/HashSet.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

-- | Hash sets. Every function of "Data.HashSet" is total, and all are
-- exported. Import qualified:
--
-- > import qualified Papa.UnorderedContainers.Data.HashSet as HashSet
--
-- Test, insert and delete an element with lens's 'Control.Lens.Contains' and
-- 'Control.Lens.At' instances: @'Papa.Lens.Optic.the' (contains a) s@,
-- @s & contains a .~ True@, @s & contains a .~ False@.
--
-- lens's instances for 'HashSet': 'Control.Lens.Contains', 'Control.Lens.At',
-- 'Control.Lens.Ixed', 'Control.Lens.AsEmpty'.
module Papa.UnorderedContainers.Data.HashSet (
  module X,
) where

import Data.HashSet as X

-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa
-- >>> import qualified Papa.UnorderedContainers.Data.HashSet as HashSet
-- >>> import Hedgehog
-- >>> import qualified Hedgehog.Gen as Gen
-- >>> import qualified Hedgehog.Range as Range
-- >>> let genElem = Gen.int (Range.linear 0 20)
-- >>> let genSet = HashSet.fromList <$> Gen.list (Range.linear 0 10) genElem

-- $examples
--
-- ==== __Examples__
--
-- >>> the (contains 2) (HashSet.fromList [1, 2 :: Int])
-- True
--
-- >>> HashSet.toList (HashSet.fromList [1 :: Int] & contains 1 .~ False)
-- []
--
-- >>> check $ withTests 100 $ property $ do s <- forAll genSet; a <- forAll genElem; the (contains a) s === HashSet.member a s
-- ...passed 100 tests.
-- True
--
-- >>> check $ withTests 100 $ property $ do s <- forAll genSet; a <- forAll genElem; (s & contains a .~ True) === HashSet.insert a s
-- ...passed 100 tests.
-- True