refactor
This commit is contained in:
parent
a7f58634b8
commit
e59ba5a70b
3 changed files with 35 additions and 22 deletions
33
Types/DeferredParse.hs
Normal file
33
Types/DeferredParse.hs
Normal file
|
@ -0,0 +1,33 @@
|
|||
{- git-annex deferred parse values
|
||||
-
|
||||
- Copyright 2015 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
|
||||
module Types.DeferredParse where
|
||||
|
||||
import Annex
|
||||
import Common
|
||||
|
||||
-- Some values cannot be fully parsed without performing an action.
|
||||
-- The action may be expensive, so it's best to call finishParse on such a
|
||||
-- value before using getParsed repeatedly.
|
||||
data DeferredParse a = DeferredParse (Annex a) | ReadyParse a
|
||||
|
||||
class DeferredParseClass a where
|
||||
finishParse :: a -> Annex a
|
||||
|
||||
getParsed :: DeferredParse a -> Annex a
|
||||
getParsed (DeferredParse a) = a
|
||||
getParsed (ReadyParse a) = pure a
|
||||
|
||||
instance DeferredParseClass (DeferredParse a) where
|
||||
finishParse (DeferredParse a) = ReadyParse <$> a
|
||||
finishParse (ReadyParse a) = pure (ReadyParse a)
|
||||
|
||||
instance DeferredParseClass (Maybe (DeferredParse a)) where
|
||||
finishParse Nothing = pure Nothing
|
||||
finishParse (Just v) = Just <$> finishParse v
|
Loading…
Add table
Add a link
Reference in a new issue