realworld-hs-0.1.0.0: Scotty impl of https://github.com/gothinkster/realworld
Safe HaskellSafe-Inferred
LanguageGHC2021

Conduit.App.Has

Synopsis

Documentation

type Has f c m = (MonadReader c m, Has' f c) Source #

Enables more semantic typing & allows for stronger free theorems. sm0rt. See grab. Unfortunately can't do the following without enabling ImpredicativeTypes which I believe isn't entirely supported, but I may be wrong there. Lmk!

type Has f m = (∀ c. MonadReader c m, ∀ c. Has' f c) :: Constraint

class Has' field container where Source #

row polymorphism my beloved

Methods

obtain :: container -> field Source #

Instances

Instances details
Has' EnvType Env Source # 
Instance details

Defined in Conduit.App.Env

Methods

obtain :: Env -> EnvType Source #

Has' DBPool Env Source # 
Instance details

Defined in Conduit.App.Env

Methods

obtain :: Env -> DBPool Source #

Has' JWTInfo Env Source # 
Instance details

Defined in Conduit.App.Env

Methods

obtain :: Env -> JWTInfo Source #

grab :: forall field container m. Has field container m => m field Source #

Works with Has

newtype Name = Name Text deriving (Show)
newtype NameBox = NameBox { nm :: Name }

instance Has' Name NameBox where 
 obtain :: NameBox -> Name
 obtain = nm

test :: (Has Name c m, MonadIO m) -> m ()
test = do
  name <- grab @Name
  print name

main :: IO ()
main = runReaderT test (NameBox $ Name "hi")