Commits

FlorianHartwig committed a7025e7

Add .: operator (stolen from aeson)

  • Participants
  • Parent commits 97c8f04

Comments (0)

Files changed (2)

src/Data/AttoBencode.hs

     , encode
     , FromBencode(..)
     , ToBencode(..)
+    , (.:)
     ) where
 
 import Data.AttoBencode.Types

src/Data/AttoBencode/Types.hs

     , Dict
     , FromBencode(..)
     , ToBencode(..)
+    , (.:)
     ) where
 
 import qualified Data.Map as M
 instance (FromBencode a) => FromBencode [a] where
     fromBencode (BList l) = sequence $ map fromBencode l
     fromBencode _         = Nothing
+
+(.:) :: (FromBencode a) => Dict -> ByteString -> Maybe a
+d .: s = M.lookup s d >>= fromBencode