module Language.Bash.Operator
( Operator(..)
, select
, selectOperator
, prettyOperator
) where
import Control.Applicative
import Data.Foldable
import Text.PrettyPrint
import Language.Bash.Pretty
class Eq a => Operator a where
operatorTable :: [(a, String)]
select :: Alternative f => (b -> f c) -> [(a, b)] -> f a
select p = asum . map (\(a, b) -> a <$ p b)
selectOperator :: (Alternative f, Operator a) => (String -> f c) -> f a
selectOperator p = select p operatorTable
prettyOperator :: Operator a => a -> Doc
prettyOperator = pretty . flip lookup operatorTable