{"id":15486648,"url":"https://github.com/dblock/enumerable-detect-value","last_synced_at":"2025-04-05T06:24:37.987Z","repository":{"id":12677953,"uuid":"15350021","full_name":"dblock/enumerable-detect-value","owner":"dblock","description":"Unlike Enumerable#detect, #detect_value returns the result of the block being evaluated.","archived":false,"fork":false,"pushed_at":"2013-12-21T18:26:17.000Z","size":124,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T18:59:52.912Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/dblock.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-20T22:48:19.000Z","updated_at":"2018-12-12T08:43:10.000Z","dependencies_parsed_at":"2022-09-04T09:40:09.771Z","dependency_job_id":null,"html_url":"https://github.com/dblock/enumerable-detect-value","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dblock%2Fenumerable-detect-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dblock%2Fenumerable-detect-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dblock%2Fenumerable-detect-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dblock%2Fenumerable-detect-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dblock","download_url":"https://codeload.github.com/dblock/enumerable-detect-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247296528,"owners_count":20915651,"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-10-02T06:09:17.633Z","updated_at":"2025-04-05T06:24:37.971Z","avatar_url":"https://github.com/dblock.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Enumerable Detect w/ Value\n==========================\n\n[![Build Status](https://travis-ci.org/dblock/enumerable-detect-value.png)](https://travis-ci.org/dblock/enumerable-detect-value)\n\n## Detect Value\n\nUnlike `Enumerable#detect`, `#detect_value` returns the result of the block being evaluated.\n\nConsider an example where you have an expensive `Geocoder.search` operation and a list of addresses, two of which are fake. The\nfunction returns `nil` for a fake address. We would like to find the geo-location of the first real address.\n\n```ruby\naddresses = [\n  '221B Baker Street, London, UK', # Sherlock Holmes\n  '1428 Elm Street, Springwood, Ohio', # Nightmare on Elm Street\n  '350 5th Ave, New York, NY' # Empire State Building\n]\n\nfirst_real_address = addresses.detect do |address|\n  Geocoder.search(address)\nend\n\nfirst_real_address # 350 5th Ave, New York, NY\n```\n\nWe do, however, want the geo-location of the first real address. We would have to call `Geocoder.search` on `first_real_address` twice.\n\nUsing `detect_value` you can return the geo-location of the first real address.\n\n```ruby\nfirst_geo_location = addresses.detect_value do |address|\n  Geocoder.search(address)\nend\n\nfirst_geo_location # lat: 40.74830, lng: -73.98554\n```\n\n## Contributing\n\nSee [CONTRIBUTING](CONTRIBUTING.md).\n\n## Copyright and License\n\nCopyright (c) 2013, Daniel Doubrovkine.\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdblock%2Fenumerable-detect-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdblock%2Fenumerable-detect-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdblock%2Fenumerable-detect-value/lists"}