{"id":15059739,"url":"https://github.com/chadtech/elm-imperative-porting","last_synced_at":"2026-04-06T09:02:13.350Z","repository":{"id":57674528,"uuid":"83948913","full_name":"Chadtech/elm-imperative-porting","owner":"Chadtech","description":"While loops in Elm","archived":false,"fork":false,"pushed_at":"2018-09-01T11:54:52.000Z","size":12,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T06:54:38.149Z","etag":null,"topics":["elm","elm-lang"],"latest_commit_sha":null,"homepage":"http://package.elm-lang.org/packages/Chadtech/elm-loop/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chadtech.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-05T06:01:55.000Z","updated_at":"2022-12-06T10:42:02.000Z","dependencies_parsed_at":"2022-08-29T17:40:55.931Z","dependency_job_id":null,"html_url":"https://github.com/Chadtech/elm-imperative-porting","commit_stats":null,"previous_names":["chadtech/elm-loop"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chadtech%2Felm-imperative-porting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chadtech%2Felm-imperative-porting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chadtech%2Felm-imperative-porting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chadtech%2Felm-imperative-porting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chadtech","download_url":"https://codeload.github.com/Chadtech/elm-imperative-porting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166242,"owners_count":21058475,"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":["elm","elm-lang"],"created_at":"2024-09-24T22:47:08.144Z","updated_at":"2025-10-27T23:06:44.629Z","avatar_url":"https://github.com/Chadtech.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elm Imperative Porting\n\nThis package is for porting code from imperative languages like C++ into Elm. Its a pretty obscure use case, so please dont feel any pressure to use it. In fact, the ideal use case for this package would conclude with you uninstalling it from your project.\n\nHow exactly does this help porting imperative code? Imperative code and ML Syntax code are pretty different. Even if you figure out how imperative code works, you cant really copy and paste it. But even that is a best case scenario, because a lot of times high performance C code is pretty much human un-readable. I get the impression that C developers are able to squeeze every bit of performance out of their code by relying on clever math and tricky programming. \n\nThis package makes it a little bit easier to port imperative code by trying to match the names and flow of imperative languages. For example, imperative code might use a while loop and theres no such thing as a while loop in functional programming. You'll need to figure out how to do that in Elm eventually, whether it be through mapping, folding, or recursion, but in the meantime you can reduce your mental overhead by just using the function in this module called `while`.\n\nBut anyway, once you port your C-syntax code into Elm and your code works, you should refactor it into something that makes sense in Elm. After that you should be able to uninstall this package from your project.\n\n\n```javascript\nvar index = 0;\nwhile (index \u003c 100) {\n  index++;\n}\n```\n\n..can be expressed using this package as as..\n\n```elm\nImperative.while ((\u003e) 100) 0 ((+) 1)\n```\n\n# Think twice before using this package.\n\nYou probably dont need this package. I made it mostly for fun. You should be mapping, folding, and using recursion most of the time. If you need to transform all the values in a list, use a map. If you need to collapse all the values in a list, use a fold. Below is an example of how to use recursion well.\n\n```elm\n-- Recusrion examples\nfirstValue : List (Maybe a) -\u003e Maybe a\nfirstValue maybes =\n    case maybes of\n        Just value :: _ -\u003e\n            Just value\n\n        Nothing :: rest -\u003e\n            firstValue rest\n\n        [] -\u003e\n            Nothing\n\n\ninsertAt : Int -\u003e a -\u003e List a -\u003e List a\ninsertAt index value list =\n    if index == 0 then\n        value :: list\n\n    else\n        case list of\n            _ :: rest -\u003e\n\n                insertAt (index - 1) value rest\n\n            [] -\u003e\n                []\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadtech%2Felm-imperative-porting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadtech%2Felm-imperative-porting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadtech%2Felm-imperative-porting/lists"}