{"id":21206577,"url":"https://github.com/oncomouse/call-me-maybe","last_synced_at":"2025-09-04T04:38:03.467Z","repository":{"id":57133141,"uuid":"117166487","full_name":"oncomouse/call-me-maybe","owner":"oncomouse","description":null,"archived":false,"fork":false,"pushed_at":"2018-01-17T15:41:23.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T08:33:47.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/oncomouse.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}},"created_at":"2018-01-11T23:32:56.000Z","updated_at":"2018-01-11T23:33:17.000Z","dependencies_parsed_at":"2022-09-03T13:25:18.256Z","dependency_job_id":null,"html_url":"https://github.com/oncomouse/call-me-maybe","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/oncomouse%2Fcall-me-maybe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncomouse%2Fcall-me-maybe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncomouse%2Fcall-me-maybe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncomouse%2Fcall-me-maybe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oncomouse","download_url":"https://codeload.github.com/oncomouse/call-me-maybe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243658270,"owners_count":20326467,"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":[],"created_at":"2024-11-20T20:56:07.339Z","updated_at":"2025-03-14T23:14:09.291Z","avatar_url":"https://github.com/oncomouse.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Travis Build Status](https://api.travis-ci.org/oncomouse/call-me-maybe.svg?branch=master)\n\n# Call Me Maybe – Daggy-based, Fantasy-Land-compliant Maybe\n\n![GIF of \"Call Me Maybe\" Video](https://media.giphy.com/media/jRfNbVMf2zqZG/giphy.gif)\n\nThis library is an implementation of the [Maybe](https://en.wikibooks.org/wiki/Haskell/Understanding_monads/Maybe) [ADT](https://en.wikipedia.org/wiki/Algebraic_data_type) based on Fantasy Land's [daggy](https://github.com/fantasyland/daggy) implementation.\n\n[Folktale](https://github.com/origamitower/folktale) contains a very good implementation of the Maybe type, but it does not implement Fantasy Land's [Alt](http://www.tomharding.me/2017/04/24/fantas-eel-and-specification-10/) specification. Additionally, Folktale's Maybe type is not easily extended, so I wrote this one, using [daggy](https://github.com/fantasyland/daggy), which uses plain objects to build ADTs and is therefore very extensible.\n\n## Installing\n\nTo install, run:\n\n~~~bash\nnpm install @oncomouse/call-me-maybe\n~~~\n\n\nOr\n\n~~~bash\nyarn add @oncomouse/call-me-maybe\n~~~\n\nYou can now run `require('@oncomouse/call-me-maybe')` to access the library.\n\n## Using on Web Pages\n\nYou can also include the library in web pages using [unpkg](https://unpkg.com):\n\n~~~html\n\u003cscript src=\"https://unpkg.com/@oncomouse/call-me-maybe/dist/call-me-maybe.min.js\"\u003e\u003c/script\u003e\n~~~\n\nThis file includes the full environment needed to use the Maybe type in your projects.\n\n## Override Equality\n\nThis library uses [epoberezkin/fast-deep-equals](https://github.com/epoberezkin/fast-deep-equal) for equality checking. It is an ok (and small) implementation. Lodash, Ramda, and Sanctuary's equality methods are all around 40K, which is a lot to implement Setoid. If, however, you want to use a different library, you can add it to Maybe by re-assigning the value of `Maybe._equals`. For instance:\n\n~~~javascript\nvar Maybe = require('@oncomouse/call-me-maybe');\nvar {equals} = require('ramda');\n\nMaybe._equals = equals; // Now using Ramda's equality check\n~~~\n\n## API\n\nTake a look at [this explanation from Fantasy Land](https://github.com/fantasyland/fantasy-land#type-signature-notation) for information on reading the function type signatures below.\n\n### Type Methods\n\nThe following methods are applied to the Typeclass itself:\n\n~~~javascript\nMaybe.of(5) // Maybe.Just(5)\nMaybe.empty() // Maybe.Nothing\nMaybe.zero() // Maybe.Nothing\n~~~\n\n#### `of` Method\n\nReturn a `Maybe.Just` instance containing the supplied data.\n\n~~~haskell\nof :: Maybe f =\u003e a -\u003e f a\n~~~\n\n#### `empty` Method\n\nReturn the empty (`Maybe.Nothing`) version of this type.\n\n~~~haskell\nempty :: Nothing\n~~~\n\n#### `zero` Method\n\nReturn the zero (`Maybe.Nothing`) version of this type.\n\n~~~haskell\nzero :: Nothing\n~~~\n\n### Member Methods\n\nThe following methods are available to members of the type:\n\n~~~javascript\nvar a = Maybe.Just(7)\nvar b = Maybe.Just(6)\nvar f = Maybe.of(x =\u003e x + 4)\n\na.equals(b) // false\na.map(x =\u003e x + 2) // Maybe.Just(9)\nf.apply(a) // Maybe.Just(11)\na.ap(f) // Maybe.Just(11)\na.chain(x =\u003e Maybe.of(x+4)) // Maybe.Just(11)\na.unsafeGet() // 7\nMaybe.Nothing.unsafeGet() // Error\na.getOrElse(5) // 7\nMaybe.Nothing.getOrElse(5) // 5\nMaybe.of([]).concat(Maybe.of([5])) // [5]\nMaybe.Nothing.fold(() =\u003e Maybe.Just(false), x =\u003e Maybe.Just(x + 1)) // Maybe.Just(false)\na.filter(x =\u003e x \u003c 5) // Maybe.Nothing\nMaybe.Nothing.alt(a) // Maybe.Just(7)\n~~~\n\n#### `equals` Method\n\nCompare the equality of one `Maybe` with another.\n\n~~~haskell\nequals :: Maybe f =\u003e f a ~\u003e f b -\u003e Boolean\n~~~\n\n#### `map` Method\n\nApply a transformation function to a `Maybe`.\n\nThe transformation function does *not* itself return a `Maybe`.\n\n~~~haskell\nmap :: Maybe f =\u003e f a ~\u003e (a -\u003e b) -\u003e f b\n~~~\n\n#### `apply` Method\n\nCalled on a `Maybe` that contains a function with a `Maybe` that contains a value, return the `Maybe` that holds the result of the function applied to the value.\n\n~~~haskell\napply :: Maybe f =\u003e f (a -\u003e b) ~\u003e f a -\u003e f b\n~~~\n\n#### `ap` Method\n\nCalled on a `Maybe` that contains a value with a `Maybe` that contains a function, return the `Maybe` that holds the result of the function applied to the value.\n\n~~~haskell\nap :: Maybe f =\u003e f a ~\u003e f (a -\u003e b) -\u003e f b\n~~~\n\n#### `chain` Method\n\nCalled on a `Maybe` that contains a value with a function that takes a value and returns a `Maybe`, return the result of that function.\n\n~~~haskell\nchain :: Maybe f =\u003e f a ~\u003e (a -\u003e f b) -\u003e f b\n~~~\n\n#### `unsafeGet` Method\n\nGet the value of a `Maybe` but will throw an error if called on `Maybe.Nothing`.\n\n~~~haskell\nunsafeGet :: Maybe f =\u003e f a ~\u003e a\n~~~\n\n#### `getOrElse` Method\n\nCalled on a `Maybe` that contains a value with another value, return the value of the `Maybe` or the default value if the `Maybe` is `Maybe.Nothing`.\n\n~~~haskell\ngetOrElse :: Maybe f =\u003e f a ~\u003e a -\u003e a\n~~~\n\n#### `concat` Method\n\nCalled on a `Maybe` whose value has a `concat()` or a `fantasy-land/concat()` method with another maybe containing the same kind of value, return a Maybe containing the result of concatenating the second value to the first.\n\n~~~haskell\nconcat :: Maybe f =\u003e f a ~\u003e f a -\u003e f a\n~~~\n\n#### `fold` Method\n\nCalled on a `Maybe` with two functions, return the result of the first if the `Maybe` is `Maybe.Nothing` and a `Maybe` with the result of the second function applied to the value of the `Maybe`.\n\n~~~haskell\nfold :: Maybe f =\u003e f a ~\u003e (_ -\u003e f b) -\u003e (a -\u003e f b) -\u003e f b\n~~~\n\n#### `filter` Method\n\nCalled on a `Maybe` and function that takes a value and returns a Boolean, either return the `Maybe` or `Maybe.Nothing` if the Boolean is `false`.\n\n~~~haskell\nfilter :: Maybe f =\u003e f a ~\u003e (a -\u003e Boolean) -\u003e f a\n~~~\n\n#### `alt` Method\n\nCalled on a `Maybe` with another `Maybe`, return the first `Maybe` unless the first is `Maybe.Nothing`, in which case return the second `Maybe`.\n\n~~~haskell\nalt :: Maybe f =\u003e f a ~\u003e f a -\u003e f a\n~~~\n\n### Fantasy Land Interface\n\nThe following methods from the API have Fantasy Land compliant equivalents:\n\n* `of` -\u003e `fantasy-land/of`\n* `empty` -\u003e `fantasy-land/empty`\n* `zero` -\u003e `fantasy-land/zero`\n* `equals` -\u003e `fantasy-land/equals`\n* `map` -\u003e `fantasy-land/map`\n* `ap` -\u003e `fantasy-land/ap`\n* `chain` -\u003e `fantasy-land/chain`\n* `concat` -\u003e `fantasy-land/concat`\n* `filter` -\u003e `fantasy-land/filter`\n* `alt` -\u003e `fantasy-land/alt`\n\nSo, for instance:\n\n~~~javascript\nequals(\n    Maybe.of([6]).concat(Maybe.of[7])\n    , Maybe['fantasy-land/of']([6])['fantasy-land/concat'](Maybe['fantasy-land/of']([7]))\n) === true\n~~~\n\n## Fantasy Land Type Implementations\n\nThis library implements the following Fantasy Land specifications:\n\n* [Setoid](https://github.com/fantasyland/fantasy-land#setoid)\n* [Semigroup](https://github.com/fantasyland/fantasy-land#semigroup)\n* [Monoid](https://github.com/fantasyland/fantasy-land#monoid)\n* [Filterable](https://github.com/fantasyland/fantasy-land#filterable)\n* [Functor](https://github.com/fantasyland/fantasy-land#monoid)\n* [Apply](https://github.com/fantasyland/fantasy-land#monoid)\n* [Applicative](https://github.com/fantasyland/fantasy-land#applicative)\n* [Alt](https://github.com/fantasyland/fantasy-land#alt)\n* [Plus](https://github.com/fantasyland/fantasy-land#plus)\n* [Alternative](https://github.com/fantasyland/fantasy-land#alternative)\n* [Chain](https://github.com/fantasyland/fantasy-land#chain)\n* [Monad](https://github.com/fantasyland/fantasy-land#monad)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foncomouse%2Fcall-me-maybe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foncomouse%2Fcall-me-maybe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foncomouse%2Fcall-me-maybe/lists"}