Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lenses #25

Merged
merged 12 commits into from
Sep 10, 2020
Merged

Feature/lenses #25

merged 12 commits into from
Sep 10, 2020

Conversation

tmrdlt
Copy link
Collaborator

@tmrdlt tmrdlt commented Sep 9, 2020

I added lenses to our project.
For the yesod models they can be added automatically by adding mpsGenerateLenses = True in Model.hs.
For the other models they have to be generated manually.
After adding lenses, fields of records can be read and manipulated using this syntax:

gameStateEntity ^. gameStateEntityStatus             -- returns "Ongoing"
gameStateEntity & gameStateEntityStatus .~ "Ongoing" -- sets Status to "Ongoing". Can be used to update multiple fields aswell. Just add more & 
gameStateEntity & gameStateEntityBombCount +~ 1      -- increments hasBomb field by 1

See also:
https://riptutorial.com/haskell/example/2987/lenses-for-records
Updating multiple fields trick:
https://mail.haskell.org/pipermail/haskell-cafe/2013-November/111288.html

I didn't use the lenses syntax for all the yesod template files as I think we are going to remove them soon anyways.

@tmrdlt tmrdlt changed the title Feature/lenses WIP Feature/lenses Sep 9, 2020
@ndrsllwngr
Copy link
Owner

Thank you for the explanation @timunkulus. Nice work!

cellsToReveal = filter (not . isFlagged)(toList board)
cellCoordinates = map coordinate cellsToReveal
cellsToReveal = filter (not . _isFlagged)(toList board)
cellCoordinates = map _coordinate cellsToReveal
resultBoard = foldl setCellToRevealed board cellCoordinates
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@griase94 wenn checkst wie man hier und weiter unten die Lense Syntax anwendet, gerne anpassen ;)

@ndrsllwngr ndrsllwngr mentioned this pull request Sep 10, 2020
46 tasks
@griase94
Copy link
Collaborator

griase94 commented Sep 10, 2020

I think we can simplyfy the revealing and flagging syntax quite a lot by using https://hackage.haskell.org/package/matrix-lens, I will give it a try after implementing the mutable state with TVars

@ndrsllwngr
Copy link
Owner

I think we can simplyfy the revealing ans flagging syntax quite a lot by using https://hackage.haskell.org/package/matrix-lens

Sounds good! Nice find.

griase94 and others added 4 commits September 10, 2020 18:23
…logic for storing paused and finished games in the database
Co-authored-by: Andreas Ellwanger <andreas.ellwanger@campus.lmu.de>
In-memory mutable state for ongoing games
@griase94 griase94 merged commit eeff5c7 into develop Sep 10, 2020
@griase94 griase94 deleted the feature/lenses branch September 10, 2020 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants