-- |
-- Module      : Data.Express.Basic
-- Copyright   : (c) 2019-2024 Rudy Matela
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : Rudy Matela <rudy@matela.com.br>
--
-- Defines the 'Expr' type and _basic_ utilities involving it, including:
--
-- * re-export of "Data.Express.Core"
-- * re-export of "Data.Express.Map"
-- * re-export of "Data.Express.Fold"
-- * re-export of "Data.Express.Hole"
--
-- If you're a Express user,
-- you're probably better of importing "Data.Express".
{-# LANGUAGE CPP #-}
module Data.Express.Basic
  (
  -- * Module re-exports
    module Data.Express.Core
  , module Data.Express.Map
  , module Data.Express.Fold
  , module Data.Express.Hole

  -- * Additional utilities
  , (>$$<)
  , (>$$)
  , ($$<)
  )
where

import Data.Express.Core
import Data.Express.Map
import Data.Express.Fold
import Data.Express.Hole

import Data.Maybe (catMaybes, mapMaybe)

-- | Lists valid applications between lists of 'Expr's
--
-- > > [notE, plus] >$$< [false, true, zero]
-- > [not False :: Bool,not True :: Bool,(0 +) :: Int -> Int]
(>$$<) :: [Expr] -> [Expr] -> [Expr]
[Expr]
efs >$$< :: [Expr] -> [Expr] -> [Expr]
>$$< [Expr]
exs  =  [Maybe Expr] -> [Expr]
forall a. [Maybe a] -> [a]
catMaybes [Expr
ef Expr -> Expr -> Maybe Expr
$$ Expr
ex | Expr
ef <- [Expr]
efs, Expr
ex <- [Expr]
exs]

-- | Lists valid applications between a list of 'Expr's and an 'Expr'.
--
-- > > [plus, times] >$$ zero
-- > [(0 +) :: Int -> Int,(0 *) :: Int -> Int]
(>$$) :: [Expr] -> Expr -> [Expr]
[Expr]
efs >$$ :: [Expr] -> Expr -> [Expr]
>$$ Expr
ex  =  (Expr -> Maybe Expr) -> [Expr] -> [Expr]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Expr -> Expr -> Maybe Expr
$$ Expr
ex) [Expr]
efs

-- | Lists valid applications between an 'Expr' and a list of 'Expr's.
--
-- > > notE >$$< [false, true, zero]
-- > [not False :: Bool,not True :: Bool]
($$<) :: Expr -> [Expr] -> [Expr]
Expr
ef $$< :: Expr -> [Expr] -> [Expr]
$$< [Expr]
exs  =  (Expr -> Maybe Expr) -> [Expr] -> [Expr]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Expr
ef Expr -> Expr -> Maybe Expr
$$) [Expr]
exs