-- http://www.codewars.com/kata/543d218022e0f307fb000173
module Foldmap where

import Data.Foldable (foldMap, Foldable)
import Data.Monoid

myToList :: Foldable t => t a -> [a]
myToList = foldMap (:[])

newtype Min a = Min { unwrap :: a }
  deriving (Eq, Ord)

instance Ord a => Monoid (Min a) where
  mempty = undefined
  mappend = min

myMinimum :: (Ord a, Foldable t) => t a -> Maybe a
myMinimum = fmap unwrap . foldMap (Just . Min)

myFoldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
myFoldr f z = foldr f z . myToList
