on 9fd59f3 help sign in
patch/src/Reflex/Patch/Class.hs
20 lines 590 B history raw
1{-# LANGUAGE TypeFamilies #-}
2module Reflex.Patch.Class where
4import Control.Monad.Identity
5import Data.Maybe
7-- | A 'Patch' type represents a kind of change made to a datastructure.
8class Patch p where
9 type PatchTarget p :: *
10 -- | Apply the patch @p a@ to the value @a@. If no change is needed, return
11 -- 'Nothing'.
12 apply :: p -> PatchTarget p -> Maybe (PatchTarget p)
14applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p
15applyAlways p t = fromMaybe t $ apply p t
17instance Patch (Identity a) where
18 type PatchTarget (Identity a) = a
19 apply (Identity a) _ = Just a