From: Ramakrishnan Muthukrishnan Date: Thu, 23 Apr 2015 07:35:34 +0000 (+0530) Subject: Bencode: make encode a bit more readable X-Git-Url: https://git.rkrishnan.org/pf/content/simplejson/statistics?a=commitdiff_plain;h=f3ac1d1ff7069ad51a244f3b8d20c5ef6ed1fc01;p=functorrent.git Bencode: make encode a bit more readable --- diff --git a/src/FuncTorrent/Bencode.hs b/src/FuncTorrent/Bencode.hs index f1a2980..3a982ec 100644 --- a/src/FuncTorrent/Bencode.hs +++ b/src/FuncTorrent/Bencode.hs @@ -16,7 +16,7 @@ import Control.Applicative ((<*)) import Data.ByteString (ByteString, length, concat) import Data.ByteString.Char8 (unpack, pack) import Data.Functor ((<$>)) -import Data.Map.Strict (Map, fromList, keys, (!)) +import Data.Map.Strict (Map, fromList, toList) import Text.ParserCombinators.Parsec import qualified Text.Parsec.ByteString as ParsecBS @@ -160,4 +160,5 @@ encode (Blist xs) = concat ["l", concat $ map encode xs, "e"] encode (Bdict d) = concat ["d", concat kvlist, "e"] where kvlist :: [ByteString] - kvlist = [concat [encode . Bstr . pack $ k , encode (d ! k)] | k <- keys d] + kvlist = [encPair kv | kv <- toList d] + encPair (k, v) = concat [encode . Bstr . pack $ k, encode v]