I am writing a pad function that takes a list and overlays it to a specific size. I tried 2 implementations:
pad :: Monoid a => Int -> [a] -> [a] pad len list = replicate (len - length list) mempty ++ list
and
pad :: Int -> a -> [a] -> [a] pad len value list = replicate (len - length list) value ++ list
The first is similar to the logical use of Monoid , but calling it with lists of integers (or everything that is Monoid several ways) is a pain:
(fmap getSum) <$> pad 8 <$> (fmap Sum) <$> [1,2,3]
Actually, I am not opposed to additional text input, but it does not even convey meaning very well. How to implement this function?
Drew source share