Last active
February 25, 2020 13:46
-
-
Save tim2CF/e0600e68d375b95bbe4c6d66fc436506 to your computer and use it in GitHub Desktop.
Nework.Wai.Application Semigroup type class instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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