delta-types-1.0.0.0: Delta types, also known as change actions.
Copyright© 2021-2023 IOHK 2024 Cardano Foundation
LicenseApache-2.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Delta.Set

Description

Delta types for Set.

Synopsis

Single element

data DeltaSet1 a Source #

Delta type for Set where a single element is deleted or added.

Constructors

Insert a 
Delete a 

Instances

Instances details
Show a => Show (DeltaSet1 a) Source # 
Instance details

Defined in Data.Delta.Set

Ord a => Delta (DeltaSet1 a) Source # 
Instance details

Defined in Data.Delta.Set

Associated Types

type Base (DeltaSet1 a) Source #

Methods

apply :: DeltaSet1 a -> Base (DeltaSet1 a) -> Base (DeltaSet1 a) Source #

Eq a => Eq (DeltaSet1 a) Source # 
Instance details

Defined in Data.Delta.Set

Methods

(==) :: DeltaSet1 a -> DeltaSet1 a -> Bool #

(/=) :: DeltaSet1 a -> DeltaSet1 a -> Bool #

Ord a => Ord (DeltaSet1 a) Source # 
Instance details

Defined in Data.Delta.Set

type Base (DeltaSet1 a) Source # 
Instance details

Defined in Data.Delta.Set

type Base (DeltaSet1 a) = Set a

The following cancellation laws hold:

apply [Insert a, Delete a] = apply (Insert a)
apply [Insert a, Insert a] = apply (Insert a)
apply [Delete a, Insert a] = apply (Delete a)
apply [Delete a, Delete a] = apply (Delete a)

Multiple elements

data DeltaSet a Source #

Delta type for a Set where collections of elements are inserted or deleted.

Instances

Instances details
Ord a => Monoid (DeltaSet a) Source # 
Instance details

Defined in Data.Delta.Set

Methods

mempty :: DeltaSet a #

mappend :: DeltaSet a -> DeltaSet a -> DeltaSet a #

mconcat :: [DeltaSet a] -> DeltaSet a #

Ord a => Semigroup (DeltaSet a) Source #

Remember that the semigroup instance is required to satisfy the following properties:

apply mempty = id
apply (d1 <> d2) = apply d1 . apply d2
Instance details

Defined in Data.Delta.Set

Methods

(<>) :: DeltaSet a -> DeltaSet a -> DeltaSet a #

sconcat :: NonEmpty (DeltaSet a) -> DeltaSet a #

stimes :: Integral b => b -> DeltaSet a -> DeltaSet a #

Ord a => Delta (DeltaSet a) Source # 
Instance details

Defined in Data.Delta.Set

Associated Types

type Base (DeltaSet a) Source #

Methods

apply :: DeltaSet a -> Base (DeltaSet a) -> Base (DeltaSet a) Source #

Eq a => Eq (DeltaSet a) Source # 
Instance details

Defined in Data.Delta.Set

Methods

(==) :: DeltaSet a -> DeltaSet a -> Bool #

(/=) :: DeltaSet a -> DeltaSet a -> Bool #

type Base (DeltaSet a) Source # 
Instance details

Defined in Data.Delta.Set

type Base (DeltaSet a) = Set a

diffSet :: Ord a => Set a -> Set a -> DeltaSet a Source #

The smallest delta that changes the second argument to the first argument.

new = apply (diffSet new old) old
diffSet (Set.fromList "ac") (Set.fromList "ab") = deltaSetFromList [Insert 'c', Delete 'b']

listFromDeltaSet :: DeltaSet a -> [DeltaSet1 a] Source #

Flatten a DeltaSet to a list of DeltaSet1.

In the result list, the set of a appearing as Insert a is disjoint from the set of a appearing as Delete a.

deltaSetFromList :: Ord a => [DeltaSet1 a] -> DeltaSet a Source #

Collect insertions or deletions of elements into a DeltaSet.

To save space, combinations of Insert and Delete for the same element are simplified when possible. These simplifications always preserve the property

apply (deltaSetFromList ds) = apply ds