| Copyright | © 2022–2026 Jonathan Knowles |
|---|---|
| License | Apache-2.0 |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.MonoidMap.Internal.NonNullMap.Merge
Description
Synopsis
- merge :: Ord k => Strategy Identity k v1 v2 v3 -> NonNullMap k v1 -> NonNullMap k v2 -> NonNullMap k v3
- mergeA :: (Applicative f, Ord k) => Strategy f k v1 v2 v3 -> NonNullMap k v1 -> NonNullMap k v2 -> f (NonNullMap k v3)
- data Strategy (f :: Type -> Type) k v1 v2 v3 = Strategy {
- withNonNullL :: !(WhenOneSideNull f k v1 v3)
- withNonNullR :: !(WhenOneSideNull f k v2 v3)
- withNonNullP :: !(WhenBothNonNull f k v1 v2 v3)
- data WhenOneSideNull (f :: Type -> Type) k vx vr
- data WhenBothNonNull (f :: Type -> Type) k v1 v2 vr
- keepNull :: forall (f :: Type -> Type) k v1 v2. Applicative f => WhenOneSideNull f k v1 v2
- keepNonNull :: forall (f :: Type -> Type) k v. Applicative f => WhenOneSideNull f k v v
- withNonNull :: forall (f :: Type -> Type) v2 v1 k. (Applicative f, MonoidNull v2) => (v1 -> v2) -> WhenOneSideNull f k v1 v2
- withNonNullA :: (Applicative f, MonoidNull v2) => (v1 -> f v2) -> WhenOneSideNull f k v1 v2
- withBoth :: forall (f :: Type -> Type) v3 v1 v2 k. (Applicative f, MonoidNull v3) => (v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
- withBothA :: (Applicative f, MonoidNull v3) => (v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
Merging
merge :: Ord k => Strategy Identity k v1 v2 v3 -> NonNullMap k v1 -> NonNullMap k v2 -> NonNullMap k v3 Source #
Merges two maps with the given Strategy.
For each key that has a non-null value in at least one of the maps, the strategy determines the value associated with that key in the merged map.
Keys that have a null value in both maps will always have a null value in the merged map.
mergeA :: (Applicative f, Ord k) => Strategy f k v1 v2 v3 -> NonNullMap k v1 -> NonNullMap k v2 -> f (NonNullMap k v3) Source #
Like merge, but for strategies with Applicative effects.
Effects are performed in increasing order of keys.
Strategies
data Strategy (f :: Type -> Type) k v1 v2 v3 Source #
A strategy for merging two maps.
A strategy determines how to compute each value in the merged map from the values associated with the same key in the two maps being merged.
A strategy has one component for every case in which at least one of the two values is non-null. There is no component for the case in which both values are null: the merged value is then always null, and the merge never needs to visit such keys.
Consequently, a binary operation f can only be implemented by a
strategy if it satisfies:
fmemptymempty==mempty
For example, the following strategy implements (<>):
Strategy{withNonNullL=keepNonNull-- v<>mempty==v ,withNonNullR=keepNonNull--mempty<>v==v ,withNonNullP=withBoth(<>)}
Constructors
| Strategy | |
Fields
| |
data WhenOneSideNull (f :: Type -> Type) k vx vr Source #
A strategy for keys that have a non-null value in one map, and a null value in the other.
Computes a result value of type vr from the non-null value of type vx.
data WhenBothNonNull (f :: Type -> Type) k v1 v2 vr Source #
A strategy for keys that have non-null values in both maps.
Computes a result value of type vr from the non-null values of types v1
and v2.
Strategies for when one side is null
keepNull :: forall (f :: Type -> Type) k v1 v2. Applicative f => WhenOneSideNull f k v1 v2 Source #
Produces a null value, discarding the non-null value.
Equivalent to , but more efficient, as it
discards entire subtrees without visiting their values.withNonNull (const mempty)
keepNonNull :: forall (f :: Type -> Type) k v. Applicative f => WhenOneSideNull f k v v Source #
Produces the non-null value unchanged.
Equivalent to , but more efficient, as it reuses entire
subtrees without testing whether their values are null.withNonNull id
withNonNull :: forall (f :: Type -> Type) v2 v1 k. (Applicative f, MonoidNull v2) => (v1 -> v2) -> WhenOneSideNull f k v1 v2 Source #
Applies the given function to the non-null value.
withNonNullA :: (Applicative f, MonoidNull v2) => (v1 -> f v2) -> WhenOneSideNull f k v1 v2 Source #
Applies the given effectful function to the non-null value.
Strategies for when both sides are non-null
withBoth :: forall (f :: Type -> Type) v3 v1 v2 k. (Applicative f, MonoidNull v3) => (v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3 Source #
Applies the given function to both non-null values.
withBothA :: (Applicative f, MonoidNull v3) => (v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3 Source #
Applies the given effectful function to both non-null values.