swarm-0.5.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Util.Erasable

Description

Custom extension of Semigroup to Monoid that adds identity + annihilator elements.

Synopsis

Documentation

data Erasable e Source #

Extend a semigroup to a monoid by adding an identity (ENothing) and an annihilator (EErase). That is,

  • ENothing <> e = e <> ENothing = e
  • EErase <> e = e <> EErase = EErase

This allows us to "erase" previous values by combining with EErase. The erasableToMaybe function turns an Erasable into a Maybe by collapsing ENothing and EErase both back into Nothing.

Constructors

ENothing 
EErase 
EJust e 

Instances

Instances details
Functor Erasable Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

fmap :: (a -> b) -> Erasable a -> Erasable b #

(<$) :: a -> Erasable b -> Erasable a #

Semigroup e => Monoid (Erasable e) Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

mempty :: Erasable e #

mappend :: Erasable e -> Erasable e -> Erasable e #

mconcat :: [Erasable e] -> Erasable e #

Semigroup e => Semigroup (Erasable e) Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

(<>) :: Erasable e -> Erasable e -> Erasable e #

sconcat :: NonEmpty (Erasable e) -> Erasable e #

stimes :: Integral b => b -> Erasable e -> Erasable e #

Show e => Show (Erasable e) Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

showsPrec :: Int -> Erasable e -> ShowS #

show :: Erasable e -> String #

showList :: [Erasable e] -> ShowS #

Eq e => Eq (Erasable e) Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

(==) :: Erasable e -> Erasable e -> Bool #

(/=) :: Erasable e -> Erasable e -> Bool #

Ord e => Ord (Erasable e) Source # 
Instance details

Defined in Swarm.Util.Erasable

Methods

compare :: Erasable e -> Erasable e -> Ordering #

(<) :: Erasable e -> Erasable e -> Bool #

(<=) :: Erasable e -> Erasable e -> Bool #

(>) :: Erasable e -> Erasable e -> Bool #

(>=) :: Erasable e -> Erasable e -> Bool #

max :: Erasable e -> Erasable e -> Erasable e #

min :: Erasable e -> Erasable e -> Erasable e #

erasable :: a -> a -> (e -> a) -> Erasable e -> a Source #

Generic eliminator for Erasable values.

erasableToMaybe :: Erasable e -> Maybe e Source #

Convert an Erasable value to Maybe, turning both ENothing and EErase into Nothing.

maybeToErasable :: Maybe e -> Erasable e Source #

Inject a Maybe value into Erasable using ENothing and EJust.