summaryrefslogtreecommitdiff
path: root/src/Data/BEncode.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-01 10:52:45 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-01 10:52:45 +0400
commit540d07ee547b0ad62b0ca1a0d8d41de8884a21ec (patch)
tree74bcb42651647133574dc9640d163fd3fed2d9de /src/Data/BEncode.hs
parentec375e0a115b2bb0211f1a6e08b1782d0e217bc2 (diff)
fix required field extraction
Diffstat (limited to 'src/Data/BEncode.hs')
-rw-r--r--src/Data/BEncode.hs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index 4a80e47..80f0108 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -68,7 +68,7 @@ class BEncodable a where
68-- bencoding = Iso (Right . toBencode) fromBEncode 68-- bencoding = Iso (Right . toBencode) fromBEncode
69 69
70decodingError :: String -> Result a 70decodingError :: String -> Result a
71decodingError s = Left ("fromBEncode: unable to match " ++ s) 71decodingError s = Left ("fromBEncode: unable to decode " ++ s)
72{-# INLINE decodingError #-} 72{-# INLINE decodingError #-}
73 73
74instance BEncodable BEncode where 74instance BEncodable BEncode where
@@ -182,7 +182,8 @@ reqKey d key
182 182
183optKey :: BEncodable a => Map ByteString BEncode -> ByteString -> Result (Maybe a) 183optKey :: BEncodable a => Map ByteString BEncode -> ByteString -> Result (Maybe a)
184optKey d key 184optKey d key
185 | Just b <- M.lookup key d = Just <$> fromBEncode b 185 | Just b <- M.lookup key d
186 , Right r <- fromBEncode b = return (Just r)
186 | otherwise = return Nothing 187 | otherwise = return Nothing
187 188
188(>--) :: BEncodable a => Map ByteString BEncode -> ByteString -> Result a 189(>--) :: BEncodable a => Map ByteString BEncode -> ByteString -> Result a