Permalink
Browse files

More specific lookup functions

  • Loading branch information...
1 parent 95c443e commit 87d7ffb07c59575c6706f957168c0e895d628878 Snoyman committed Mar 5, 2010
Showing with 28 additions and 2 deletions.
  1. +27 −0 Data/Object/Base.hs
  2. +0 −1 Data/Object/Scalar.hs
  3. +1 −1 data-object.cabal
View
@@ -64,6 +64,9 @@ module Data.Object.Base
, deriveSuccessConvs
-- * Helper functions
, lookupObject
+ , lookupScalar
+ , lookupSequence
+ , lookupMapping
-- * Re-export
, module Data.Convertible.Text
) where
@@ -346,3 +349,27 @@ lookupObject :: ( ConvertSuccess k' k
-> [(k, Object k v)]
-> Attempt o
lookupObject key = ca <=< A.lookup (convertSuccess key)
+
+lookupScalar :: ( MonadFailure ObjectExtractError m
+ , Failure (A.LookupFailure k) m
+ , Eq k)
+ => k
+ -> [(k, Object k v)]
+ -> m v
+lookupScalar key = fromScalar <=< A.lookup key
+
+lookupSequence :: ( MonadFailure ObjectExtractError m
+ , Failure (A.LookupFailure k) m
+ , Eq k)
+ => k
+ -> [(k, Object k v)]
+ -> m [Object k v]
+lookupSequence key = fromSequence <=< A.lookup key
+
+lookupMapping :: ( MonadFailure ObjectExtractError m
+ , Failure (A.LookupFailure k) m
+ , Eq k)
+ => k
+ -> [(k, Object k v)]
+ -> m [(k, Object k v)]
+lookupMapping key = fromMapping <=< A.lookup key
@@ -27,7 +27,6 @@ import Data.Object.Base
import System.Locale (defaultTimeLocale)
import Data.Time.Format (formatTime)
import Data.Attempt
-import Data.Convertible.Text
data Scalar = Numeric Rational
| Text Text
View
@@ -1,5 +1,5 @@
name: data-object
-version: 0.2.0.1
+version: 0.2.1
license: BSD3
license-file: LICENSE
author: Michael Snoyman, Nicolas Pouillard

0 comments on commit 87d7ffb

Please sign in to comment.