{"id":13555005,"url":"https://github.com/fantasyland/static-land","last_synced_at":"2025-04-04T14:05:56.297Z","repository":{"id":50521482,"uuid":"53745720","full_name":"fantasyland/static-land","owner":"fantasyland","description":"Specification for common algebraic structures in JavaScript based on Fantasy Land","archived":false,"fork":false,"pushed_at":"2019-10-29T13:34:03.000Z","size":120,"stargazers_count":775,"open_issues_count":11,"forks_count":41,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-29T05:09:58.148Z","etag":null,"topics":["adt","algebra","algebraic","algebraic-data-types","fantasy-land","functional-programming","functor","monad","monoid","specification","static-land"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/fantasyland.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":"2016-03-12T18:04:07.000Z","updated_at":"2025-03-23T10:43:50.000Z","dependencies_parsed_at":"2022-09-26T16:41:04.897Z","dependency_job_id":null,"html_url":"https://github.com/fantasyland/static-land","commit_stats":null,"previous_names":["rpominov/static-land"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasyland%2Fstatic-land","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasyland%2Fstatic-land/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasyland%2Fstatic-land/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasyland%2Fstatic-land/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fantasyland","download_url":"https://codeload.github.com/fantasyland/static-land/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190188,"owners_count":20898697,"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":["adt","algebra","algebraic","algebraic-data-types","fantasy-land","functional-programming","functor","monad","monoid","specification","static-land"],"created_at":"2024-08-01T12:02:59.628Z","updated_at":"2025-04-04T14:05:56.282Z","avatar_url":"https://github.com/fantasyland.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others","📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"readme":"# \u003cimg width=\"80\" height=\"50\" src=\"./logo/logo.png\" /\u003e Static Land\n\nThis is a specification for common algebraic structures in JavaScript\nbased on [Fantasy Land](https://github.com/fantasyland/fantasy-land).\n\n* [Specification](docs/spec.md)\n\n### Difference from Fantasy Land\n\nFantasy Land uses methods to define interfaces that a type must implement in\norder to support a particular Algebra. For example values of a type that\nimplements the Monoid algebra must have `fantasy-land/empty` and\n`fantasy-land/concat` methods on them.\n\nStatic Land takes a different approach. Instead of methods, we use static\nfunctions, that are grouped together in [modules](docs/spec.md#module).\n\nFor example, here is an Addition module that uses numbers as values and\nsatisfies the Monoid algebra requirements:\n\n```js\nconst Addition = {\n\n  empty() {\n    return 0\n  },\n\n  concat(a, b) {\n    return a + b\n  },\n\n}\n```\n\n#### Pros\n\n  - No name clashes. Since a module is just a collection of functions that don't\n    share any namespace we don't have problems with name clashes.\n  - We can implement many modules for one type, therefore we can have more than\n    one instance of the same Algebra for a single type. For example, we can\n    implement two Monoids for numbers: Addition and Multiplication.\n  - We can implement modules that work with built-in types as values (Number,\n    Boolean, Array, etc).\n\n#### Cons\n\n  - We have to pass around modules when we write generic code. In Fantasy Land\n    most of generic code can be written using only methods, only if we need\n    methods like `of` or `empty` we might need to pass the type representative.\n    ([This can be fixed!](https://github.com/rpominov/static-land/issues/45))\n\n### How to add compatibility with Static Land to your library\n\nSimply expose a [module](docs/spec.md#module) that works with types that your\nlibrary provides or with types defined in another library or with native types\nlike Array.\n\nModules don't have to be simple JavaScript objects; they can also be\nconstructors if desired. The only requirements are:\n\n- this object contains some static methods from Static Land; and\n- if it contains a method with one of the names that Static Land reserves, that\n  method must be the Static Land method (obey laws etc).\n\n#### Example 1. Static Land module for Array\n\n```js\nconst SArray = {\n\n  of(x) {\n    return [x]\n  },\n\n  map(fn, arr) {\n    return arr.map(fn)\n  },\n\n  chain(fn, arr) {\n    // ...\n  },\n\n}\n\nexport {SArray}\n```\n\n#### Example 2. Static Land module as a Class\n\n```js\nclass MyType {\n\n  constructor() {\n    // ...\n  }\n\n  someInstanceMethod() {\n    // ...\n  }\n\n  static someNonStaticLandStaticMethod() {\n    // ...\n  }\n\n\n  // Static Land methods\n\n  static of(x) {\n    // ...\n  }\n\n  static map(fn, value) {\n    // ...\n  }\n\n}\n\nexport {MyType}\n```\n\n\n#### Example 3. Static Land module as ECMAScript modules\n\n```js\n// mytype.js\n\n// Static Land methods\n\nexport function of(x) {\n  // ...\n}\n\nexport function map(fn, value) {\n  // ...\n}\n```\n\nImport as\n\n```js\nimport * as MyType from \"./mytype\" // MyType is now a Static Land module\n```\n\n### Compatible libraries\n\nWe have a list in the wiki. Feel free to add your library there.\n\n- [Compatible libraries](https://github.com/rpominov/static-land/wiki/Compatible-libraries)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasyland%2Fstatic-land","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffantasyland%2Fstatic-land","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasyland%2Fstatic-land/lists"}