Bryan O'Sullivan avatar Bryan O'Sullivan committed 58c0404

Implement and test transpose

Comments (0)

Files changed (2)


     , map
     , intercalate
     , intersperse
-    -- , transpose
+    , transpose
     -- , reverse
     -- * Folds
 intersperse c t = unstream (S.intersperse c (stream t))
 {-# INLINE intersperse #-}
+-- | /O(n)/ The 'transpose' function transposes the rows and columns
+-- of its 'Text' argument.  Note that this function uses 'pack',
+-- 'unpack', and the list version of transpose, and is thus not very
+-- efficient.
+transpose :: [Text] -> [Text]
+transpose ts = (\ss -> Chunk (T.pack ss) Empty)
+                     (L.transpose ( unpack ts))
+-- TODO: make this fast
 -- | /O(n)/ 'foldl', applied to a binary operator, a starting value
 -- (typically the left-identity of the operator), and a 'Text',
 -- reduces the 'Text' using the binary operator, from left to right.


 prop_T_intersperse c   = L.intersperse c `eqP` (unpackT . T.intersperse c)
 prop_TL_intersperse c  = L.intersperse c `eqP` (unpackT . TL.intersperse c)
 prop_T_transpose       = L.transpose `eq` (map unpackT . T.transpose . map T.pack)
+prop_TL_transpose      = L.transpose `eq` (map unpackT . TL.transpose . map TL.pack)
 prop_T_reverse         = L.reverse `eqP` (unpackT . T.reverse)
 prop_T_reverse_short n = L.reverse `eqP` (unpackT . S.reverse . shorten n .
   ("prop_T_intersperse", mytest prop_T_intersperse),
   ("prop_TL_intersperse", mytest prop_TL_intersperse),
   ("prop_T_transpose", mytest prop_T_transpose),
+  ("prop_TL_transpose", mytest prop_TL_transpose),
   ("prop_T_reverse", mytest prop_T_reverse),
   ("prop_T_reverse_short", mytest prop_T_reverse_short),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.