{"id":16336405,"url":"https://github.com/justinwoo/purescript-hotteok","last_synced_at":"2026-02-12T09:03:28.686Z","repository":{"id":58231116,"uuid":"127616421","full_name":"justinwoo/purescript-hotteok","owner":"justinwoo","description":"A thing for working with JSUnions by guarding members and otherwise creating and extracting members.","archived":false,"fork":false,"pushed_at":"2018-08-09T12:44:47.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-12T15:34:01.567Z","etag":null,"topics":["ffi","occurence-typing","purescript","union"],"latest_commit_sha":null,"homepage":"https://pursuit.purescript.org/packages/purescript-hotteok/0.1.0","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justinwoo.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":"2018-04-01T09:44:27.000Z","updated_at":"2025-12-27T19:57:52.000Z","dependencies_parsed_at":"2022-08-30T20:01:45.853Z","dependency_job_id":null,"html_url":"https://github.com/justinwoo/purescript-hotteok","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/justinwoo/purescript-hotteok","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fpurescript-hotteok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fpurescript-hotteok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fpurescript-hotteok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fpurescript-hotteok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinwoo","download_url":"https://codeload.github.com/justinwoo/purescript-hotteok/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinwoo%2Fpurescript-hotteok/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29362205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ffi","occurence-typing","purescript","union"],"created_at":"2024-10-10T23:44:02.473Z","updated_at":"2026-02-12T09:03:28.667Z","avatar_url":"https://github.com/justinwoo.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PureScript-Hotteok\n\nA thing for working with JSUnions by guarding members and otherwise creating and extracting members.\n\n![](https://i.imgur.com/N4xa6La.png)\n\nSee [the tests](test/Main.purs) for all of the examples.\n\n### Further Reading\n\nYou may be interested in reading my blog posts accompanying this library explaining some motivations and methods for implemenation:\n\n* Matching on JS Union members with Row Types (Handling JS Unions cont.): \u003chttps://qiita.com/kimagure/items/7a0d1675522c09b4bcb6\u003e\n\n* Handling JS Unions with Row Types: \u003chttps://qiita.com/kimagure/items/141423771ad1f5a84425\u003e\n\n## Examples:\n\n### Guarding a two-member union and extracting out the remaining singleton\n\n```purs\ntype TestUnion = H.JSUnion\n  ( name :: String\n  , count :: Int\n  )\n\nnameP = SProxy :: SProxy \"name\"\ncountP = SProxy :: SProxy \"count\"\n\ncountGuard :: H.UnsafeGuardFor \"count\" Int\ncountGuard =\n  H.UnsafeGuardFor\n      $ isRight\n    \u003c\u003c\u003c runExcept\n    \u003c\u003c\u003c readInt\n\nnameGuard :: H.UnsafeGuardFor \"name\" String\nnameGuard =\n  H.UnsafeGuardFor\n     $ isRight\n   \u003c\u003c\u003c runExcept\n   \u003c\u003c\u003c readString\n\n-- ...\n    T.test \"unsafeGuardMember 1\" do\n      let\n        (union :: TestUnion) = H.fromMember nameP \"banana\"\n        guarded = H.unsafeGuardMember countGuard union\n      case guarded of\n        Right e -\u003e\n          T.failure \"incorrect branch from JSUnion\"\n        Left singleton -\u003e do\n          let value = H.unsafeExtractSingleton singleton\n          Assert.equal value \"banana\"\n```\n\n### Matching on union members, with a Nothing returned for no matches\n\n```hs\n-- ...\n    T.test \"matchMembers 1\" do\n      let\n        (union :: TestUnion) = H.fromMember countP 1\n        match = H.matchJSUnion\n          { count: Tuple countGuard show\n          , name: Tuple nameGuard identity\n          }\n          union\n      case match of\n        Just value -\u003e do\n          Assert.equal value \"1\"\n        Nothing -\u003e\n          T.failure \"incorrect result from matchJSUnion\"\n\n    T.test \"matchMembers 2\" do\n      let\n        (union :: TestUnion) = unsafeCoerce { crap: \"some bullshit from JS\" }\n        match = H.matchJSUnion\n          { count: Tuple countGuard show\n          , name: Tuple nameGuard identity\n          }\n          union\n      case match of\n        Just value -\u003e do\n          T.failure \"incorrect result from matchJSUnion\"\n        Nothing -\u003e\n          T.success\n```\n\n### Using Chalk.js properties as both functions and objects\n\n```purs\nchalkMain :: Effect Unit\nchalkMain = do\n  let\n    fnP = SProxy :: SProxy \"fn\"\n    objP = SProxy :: SProxy \"obj\"\n    blueFn = H.unsafeCoerceMember fnP chalk.blue\n    blueObj = H.unsafeCoerceMember objP chalk.blue\n  log $ blueFn \"blue text\"\n  log $ blueObj.bgYellow \"yellow background blue text\"\n\nforeign import chalk\n  :: { blue\n       :: H.JSUnion\n            ( fn :: String -\u003e String\n            , obj :: { bgYellow :: String -\u003e String }\n            )\n     }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinwoo%2Fpurescript-hotteok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinwoo%2Fpurescript-hotteok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinwoo%2Fpurescript-hotteok/lists"}