diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-13 17:27:54 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-13 17:27:54 -0400 |
commit | cc6775a52107f5425d668a4831f475d05dc113b5 (patch) | |
tree | f9172a947fb6950712e1c7d0d002d3c40c1c6672 /lib/KeyRing/Types.hs | |
parent | 6a60cc1621afcbf16fe86af1d782973dec319b3b (diff) |
WIP: encapsulation of KeyDB.
Diffstat (limited to 'lib/KeyRing/Types.hs')
-rw-r--r-- | lib/KeyRing/Types.hs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/KeyRing/Types.hs b/lib/KeyRing/Types.hs index 0797dab..3c1f0a5 100644 --- a/lib/KeyRing/Types.hs +++ b/lib/KeyRing/Types.hs | |||
@@ -1,8 +1,10 @@ | |||
1 | {-# LANGUAGE DeriveFunctor #-} | 1 | {-# LANGUAGE DeriveFunctor #-} |
2 | {-# LANGUAGE PatternSynonyms #-} | 2 | {-# LANGUAGE DeriveTraversable #-} |
3 | {-# LANGUAGE PatternSynonyms #-} | ||
3 | module KeyRing.Types where | 4 | module KeyRing.Types where |
4 | 5 | ||
5 | import Data.Char (isLower,toLower) | 6 | import Data.Char (isLower,toLower) |
7 | import Data.Functor | ||
6 | import Data.List (groupBy,find) | 8 | import Data.List (groupBy,find) |
7 | import Data.Map as Map (Map) | 9 | import Data.Map as Map (Map) |
8 | import qualified Data.Map as Map | 10 | import qualified Data.Map as Map |
@@ -272,7 +274,7 @@ data KikiCondition a = KikiSuccess a | |||
272 | | NoWorkingKey | 274 | | NoWorkingKey |
273 | | AgentConnectionFailure | 275 | | AgentConnectionFailure |
274 | | OperationCanceled | 276 | | OperationCanceled |
275 | deriving ( Functor, Show ) | 277 | deriving ( Functor, Foldable, Traversable, Show ) |
276 | 278 | ||
277 | instance FunctorToMaybe KikiCondition where | 279 | instance FunctorToMaybe KikiCondition where |
278 | functorToMaybe (KikiSuccess a) = Just a | 280 | functorToMaybe (KikiSuccess a) = Just a |
@@ -287,6 +289,11 @@ instance Applicative KikiCondition where | |||
287 | Left err -> err | 289 | Left err -> err |
288 | Left err -> err | 290 | Left err -> err |
289 | 291 | ||
292 | instance Monad KikiCondition where | ||
293 | return = pure | ||
294 | KikiSuccess a >>= f = f a | ||
295 | kikiCondition >>= f = kikiCondition <&> error (show (const () <$> kikiCondition) ++ " >>= f") | ||
296 | |||
290 | uncamel :: String -> String | 297 | uncamel :: String -> String |
291 | uncamel str = unwords $ firstWord ++ (toLower .: otherWords) ++ args | 298 | uncamel str = unwords $ firstWord ++ (toLower .: otherWords) ++ args |
292 | where | 299 | where |