Skip to content

Instantly share code, notes, and snippets.

@scott-fleischman
Created February 27, 2015 20:31
Show Gist options
  • Save scott-fleischman/f8506aff047349793528 to your computer and use it in GitHub Desktop.
Save scott-fleischman/f8506aff047349793528 to your computer and use it in GitHub Desktop.
Lists with padding
-- 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