{"id":19081673,"url":"https://github.com/smachave/some","last_synced_at":"2026-06-17T18:31:26.909Z","repository":{"id":91007873,"uuid":"478068652","full_name":"smachave/some","owner":"smachave","description":"`unless var.nil?` as a block","archived":false,"fork":false,"pushed_at":"2022-04-08T16:19:55.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-09T15:23:56.241Z","etag":null,"topics":["functional-programming","monad"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/smachave.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-05T09:58:10.000Z","updated_at":"2023-03-05T05:32:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"4515d1f8-77c4-4cb2-b164-4dae146973ea","html_url":"https://github.com/smachave/some","commit_stats":null,"previous_names":["smachave/some"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/smachave/some","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smachave%2Fsome","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smachave%2Fsome/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smachave%2Fsome/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smachave%2Fsome/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smachave","download_url":"https://codeload.github.com/smachave/some/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smachave%2Fsome/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34461616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["functional-programming","monad"],"created_at":"2024-11-09T02:38:13.704Z","updated_at":"2026-06-17T18:31:26.882Z","avatar_url":"https://github.com/smachave.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# some\n\nInspired by `Option.map` in Scala.\n\n`unless var.nil?`, but as a block. Might save a few lines ;)\n\n```crystal\n/\\d+/.match(\"n1.txt\").fmap do |match_data|  # =\u003e (MatchData | Nil)\n  match_data[0].fmap do |level_str|         # =\u003e (String | Nil)\n    level_str.to_i32                        # =\u003e 1\n  end\nend\n```\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     some:\n       github: tkshnwesper/some\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"some\"\n\npossibly_nil : String | Nil\n\npossibly_nil = \"Hello\"\n\nSome.new(possibly_nil).fmap do |definitely_not_nil|\n  puts \"#{definitely_not_nil}! Greetings, young 'un!\" # gets executed as expected!\nend\n\npossibly_nil = nil\n\nSome.new(possibly_nil).fmap do\n  `rm -rf /` # this won't get executed\nend\n```\n\n### Object extension\n\nYou may also use the lib by enabling object extensions.\n```crystal\nsome_object_extension(:some_map) # takes an optional parameter which sets method name (default: fmap)\n\nresult = 10.some_map do |value|\n  value.to_s\nend\n\nputs result # =\u003e 10\n```\n\nUsing `Some.new` would fail the compilation whenever the parameter passed cannot be `nil`. For example, `Some.new(\"hello\")` would give compilation error.\n\nHowever, the object extension can be used even on those objects which do not have `Nil` in their union type. For example `\"hello\".fmap` would not result in a compilation error.\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/tkshnwesper/some/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [tkshnwesper](https://github.com/tkshnwesper) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmachave%2Fsome","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmachave%2Fsome","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmachave%2Fsome/lists"}