Skip to content

Instantly share code, notes, and snippets.

@tim2CF
Last active February 25, 2020 13:46
Show Gist options
  • Save tim2CF/e0600e68d375b95bbe4c6d66fc436506 to your computer and use it in GitHub Desktop.
Save tim2CF/e0600e68d375b95bbe4c6d66fc436506 to your computer and use it in GitHub Desktop.
Nework.Wai.Application Semigroup type class instance
{-# LANGUAGE InstanceSigs #-}
module Wai.Network.Middleware.WaiSemigroup (WaiApp(..)) where
import Data.Coerce (coerce)
import Network.HTTP.Types.Status (status404)
import Network.Wai (Application, responseStatus)
newtype WaiApp = WaiApp Application
instance Semigroup WaiApp where
(<>) :: WaiApp -> WaiApp -> WaiApp
(<>) app0 app1 = WaiApp $ \req respond ->
coerce
app0
req
( \res ->
if responseStatus res == status404
then coerce app1 req respond
else respond res
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment