Last active
June 18, 2020 19:09
-
-
Save goertzenator/2c055e96679c373a47cb894580725317 to your computer and use it in GitHub Desktop.
Polysemy State and Lens
This file contains 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
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 = | |
$ 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