Skip to content

Instantly share code, notes, and snippets.

@goertzenator
Last active June 18, 2020 19:09
Show Gist options
  • Save goertzenator/2c055e96679c373a47cb894580725317 to your computer and use it in GitHub Desktop.
Save goertzenator/2c055e96679c373a47cb894580725317 to your computer and use it in GitHub Desktop.
Polysemy State and Lens
stateToStateViaLens :: Member (State bigSt) r
=> Lens' bigSt smallSt
-> Sem (State smallSt ': r) a
-> Sem r a
stateToStateViaLens lens = interpret $ \case
Put smallSt -> modify' (set lens smallSt)
Get -> gets (view lens)
trylensplay2 :: IO ()
trylensplay2 =
print
$ run
$ runState (5,10)
$ stateToStateViaLens
$ lensplay2
lensplay2 :: Member (State (Int, Int)) r => Sem r String
lensplay2 = do
_1 *= 2
_2 += 10
pure "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment