Skip to content

Commit

Permalink
Generalize case_ to work on any Predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ocharles committed Mar 17, 2017
1 parent c8e76fb commit 49e9864
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Rel8/Internal/Operators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

module Rel8.Internal.Operators where

import Control.Arrow ((***))
import Data.Int (Int16, Int32, Int64)
import Data.Text (Text)
import Data.Time (UTCTime)
Expand Down Expand Up @@ -102,9 +101,12 @@ instance DBOrd UTCTime where

-- | Case statement. @case_ [(x,a), (y, b)] c@ corresponds to
-- @CASE WHEN x THEN a WHEN y THEN b ELSE c END@.
case_ :: [(Expr Bool, Expr a)] -> Expr a -> Expr a
case_ :: Predicate bool => [(Expr bool, Expr a)] -> Expr a -> Expr a
case_ cases defaultCase =
columnToExpr
(O.case_
(map (exprToColumn *** exprToColumn) cases)
(exprToColumn defaultCase))
(map
(\(predicate, when) ->
(exprToColumn (toNullable predicate), exprToColumn when))
cases)
(exprToColumn defaultCase))

0 comments on commit 49e9864

Please sign in to comment.