From f3ac1d1ff7069ad51a244f3b8d20c5ef6ed1fc01 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Thu, 23 Apr 2015 13:05:34 +0530
Subject: [PATCH] Bencode: make encode a bit more readable

---
 src/FuncTorrent/Bencode.hs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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]
-- 
2.45.2