Created
February 27, 2015 20:31
-
-
Save scott-fleischman/f8506aff047349793528 to your computer and use it in GitHub Desktop.
Lists with padding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- taken from http://stackoverflow.com/questions/21349408/zip-with-default-value-instead-of-dropping-values/21350096#21350096 | |
module Main where | |
import Control.Applicative | |
import Data.Traversable | |
import Data.List | |
data Padme m = (:-) | |
{ padded :: [m] | |
, padder :: m | |
} | |
deriving (Show, Eq) | |
instance Applicative Padme where | |
pure = ([] :-) | |
(fs :- f) <*> (ss :- s) = zapp fs ss :- f s where | |
zapp [] ss = map f ss | |
zapp fs [] = map ($ s) fs | |
zapp (f : fs) (s : ss) = f s : zapp fs ss | |
instance Functor Padme where | |
fmap = (<*>) . pure | |
deggar :: [String] -> [String] | |
deggar = transpose . padded . traverse (:- ' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment