{"id":19938635,"url":"https://github.com/sectore/program-imperatively-using-purescript","last_synced_at":"2025-03-01T12:44:35.194Z","repository":{"id":66673198,"uuid":"80365222","full_name":"sectore/program-imperatively-using-purescript","owner":"sectore","description":"Program imperatively using PureScript, State monad and lenses","archived":false,"fork":false,"pushed_at":"2018-09-09T11:32:21.000Z","size":70,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-12T04:06:35.276Z","etag":null,"topics":["lenses","purescript"],"latest_commit_sha":null,"homepage":"","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sectore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-29T18:56:52.000Z","updated_at":"2024-08-07T17:51:33.000Z","dependencies_parsed_at":"2023-03-09T08:31:08.132Z","dependency_job_id":null,"html_url":"https://github.com/sectore/program-imperatively-using-purescript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectore%2Fprogram-imperatively-using-purescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectore%2Fprogram-imperatively-using-purescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectore%2Fprogram-imperatively-using-purescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectore%2Fprogram-imperatively-using-purescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sectore","download_url":"https://codeload.github.com/sectore/program-imperatively-using-purescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241367932,"owners_count":19951444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lenses","purescript"],"created_at":"2024-11-12T23:41:24.716Z","updated_at":"2025-03-01T12:44:35.160Z","avatar_url":"https://github.com/sectore.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Program imperatively with PureScript using `State` and `Lenses`\n\n\u003e I guess people really aren't joking when they say Haskell is the finest imperative language.\n\n_Quote by Gabriel Gonzalez at his famous blog post [\"Program imperatively using Haskell lenses\"](http://www.haskellforall.com/2013/05/program-imperatively-using-haskell.html)_\n\n:space_invader: :space_invader: :space_invader: **Let's have with PureScript an another _finest_ imperative language!** :space_invader: :space_invader: :space_invader:\n\nThat's why you will find here all code of [`Program imperatively using Haskell lenses`](http://www.haskellforall.com/2013/05/program-imperatively-using-haskell.html) (originally written by [@Gabriel439](https://github.com/Gabriel439)) ported to  [PureScript](http://www.purescript.org/).\n\nThe fun part with `lenses` are supported by  [`purescript-profunctor-lenses`](https://github.com/purescript-contrib/purescript-profunctor-lenses/)\n\nHave fun :sunglasses:\n\n## How to ...?\n\n### Read the code\n\nTo understand all code start to read the [original Haskell tutorial](http://www.haskellforall.com/2013/05/program-imperatively-using-haskell.html). Compare the [original Haskell examples](http://www.haskellforall.com/2013/05/program-imperatively-using-haskell.html) with the following PureScript files:\n* [Game.purs](./src/Game.purs) (state manipulation w/ lenses)\n* [Lenses.purs](./src/Lenses.purs) (lenses generated by [`purescript-derive-lenses`](https://github.com/paf31/purescript-derive-lenses))\n* [Data.purs](./src/Data.purs) (all types)\n* [Main.purs](./src/Main.purs) (output of all results to console)\n\n### Run\n\n```bash\nnpm install\nnpm start\n```\n\n### Output\n\n```bash\n\n##################\nGetter / Setter\n##################\n\n# get score\n0\n\n# set score\n(Game { boss: (GameUnit { health: 100, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 10000, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 15, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 8, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n# update score\n(Game { boss: (GameUnit { health: 100, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 222, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 15, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 8, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n##################\nComposition\n##################\n\n# strike\n*shink*\n(Game { boss: (GameUnit { health: 133, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 15, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 8, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n# strike'\n*shink*\n(Game { boss: (GameUnit { health: 133, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 15, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 8, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n##################\nTraversal\n##################\n\n# fireBreath\n*srawr*\n(Game { boss: (GameUnit { health: 100, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 7, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 12, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 5, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n# fireBreath'\n*srawr*\n(Game { boss: (GameUnit { health: 100, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 7.0 }) }),(GameUnit { health: 12, position: (GamePoint { x: 1.0, y: 1.0 }) }),(GameUnit { health: 5, position: (GamePoint { x: 0.0, y: 2.1 }) })] })\n\n##################\nZooming\n##################\n\n# partyLoc\n((GamePoint { x: 3.5, y: 7.0 }) : (GamePoint { x: 1.0, y: 1.0 }) : (GamePoint { x: 0.0, y: 2.1 }) : Nil)\n\n# retreat\nRetreat!\n(Game { boss: (GameUnit { health: 100, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 17.0 }) }),(GameUnit { health: 15, position: (GamePoint { x: 1.0, y: 11.0 }) }),(GameUnit { health: 8, position: (GamePoint { x: 0.0, y: 12.1 }) })] })\n\n# retreat newstate\nRetreat!\n((GamePoint { x: 3.5, y: 17.0 }) : (GamePoint { x: 1.0, y: 11.0 }) : (GamePoint { x: 0.0, y: 12.1 }) : Nil)\nRetreat!\n((GamePoint { x: 3.5, y: 17.0 }) : (GamePoint { x: 1.0, y: 11.0 }) : (GamePoint { x: 0.0, y: 12.1 }) : Nil)\n\n##################\nCombining\n##################\n\n# battle\nTake that!\n*shink*\nand that!\n*shink*\nand that!\n*shink*\n*srawr*\nRetreat!\nRetreat!\nRetreat!\n(Game { boss: (GameUnit { health: 199, position: (GamePoint { x: 0.0, y: 0.0 }) }), score: 0, units: [(GameUnit { health: 10, position: (GamePoint { x: 3.5, y: 67.0 }) }),(GameUnit { health: 12, position: (GamePoint { x: 1.0, y: 61.0 }) }),(GameUnit { health: 5, position: (GamePoint { x: 0.0, y: 62.1 }) })] })\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectore%2Fprogram-imperatively-using-purescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsectore%2Fprogram-imperatively-using-purescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectore%2Fprogram-imperatively-using-purescript/lists"}