mirror of
https://github.com/github/semantic.git
synced 2025-01-08 08:30:27 +03:00
Document declarations in Patch.hs
This commit is contained in:
parent
640449e2f3
commit
9c272a40d7
@ -1,20 +1,24 @@
|
||||
module Patch where
|
||||
|
||||
-- | An operation to replace, insert, or delete an item.
|
||||
data Patch a =
|
||||
Replace a a
|
||||
| Insert a
|
||||
| Delete a
|
||||
deriving (Functor, Show, Eq)
|
||||
|
||||
-- | Return the item from the after side of the patch.
|
||||
after :: Patch a -> Maybe a
|
||||
after (Replace _ a) = Just a
|
||||
after (Insert a) = Just a
|
||||
after _ = Nothing
|
||||
|
||||
-- | Return the item from the before side of the patch.
|
||||
before :: Patch a -> Maybe a
|
||||
before (Replace a _) = Just a
|
||||
before (Delete a) = Just a
|
||||
before _ = Nothing
|
||||
|
||||
-- | Calculate the cost of the patch given a function to compute the cost of a item.
|
||||
patchSum :: (a -> Integer) -> Patch a -> Integer
|
||||
patchSum termCost patch = (maybe 0 termCost $ before patch) + (maybe 0 termCost $ after patch)
|
||||
|
Loading…
Reference in New Issue
Block a user