{-# OPTIONS_GHC -fno-warn-orphans #-}

module Yesod.Form.Fields.Instances
  () where

import ClassyPrelude hiding (foldMap)
import Yesod.Form.Fields

import Data.Foldable (Foldable(..))


deriving instance Foldable Option
deriving instance Traversable Option

instance Foldable OptionList where
  foldMap f OptionList{..} = foldMap (foldMap f) olOptions


instance Semigroup (OptionList a) where
  a <> b = OptionList
    { olOptions      = olOptions a <> olOptions b
    , olReadExternal = \inp -> olReadExternal a inp <|> olReadExternal b inp
    }

instance Monoid (OptionList a) where
  mempty = OptionList
    { olOptions      = mempty
    , olReadExternal = const Nothing
    }
