{"action":"created","issue":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/1871","labels_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1871/labels{/name}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1871/comments","events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1871/events","html_url":"https://github.com/bbatsov/rubocop/pull/1871","id":73854405,"number":1871,"title":"Sample: support shuffle randomness source and first/last params","user":{"login":"chastell","id":56633,"avatar_url":"https://avatars.githubusercontent.com/u/56633?v=3","gravatar_id":"","url":"https://api.github.com/users/chastell","html_url":"https://github.com/chastell","followers_url":"https://api.github.com/users/chastell/followers","following_url":"https://api.github.com/users/chastell/following{/other_user}","gists_url":"https://api.github.com/users/chastell/gists{/gist_id}","starred_url":"https://api.github.com/users/chastell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chastell/subscriptions","organizations_url":"https://api.github.com/users/chastell/orgs","repos_url":"https://api.github.com/users/chastell/repos","events_url":"https://api.github.com/users/chastell/events{/privacy}","received_events_url":"https://api.github.com/users/chastell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-05-07T05:45:43Z","updated_at":"2015-05-09T21:07:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bbatsov/rubocop/pulls/1871","html_url":"https://github.com/bbatsov/rubocop/pull/1871","diff_url":"https://github.com/bbatsov/rubocop/pull/1871.diff","patch_url":"https://github.com/bbatsov/rubocop/pull/1871.patch"},"body":"`Performance/Sample` registers the below as an offense:\r\n\r\n```Ruby\r\n[1, 2, 3].shuffle(random: foo).find(&:bar)\r\n```\r\n\r\nI believe [I have a valid use-case](https://github.com/chastell/signore/commit/1b6c1f0fbc963753e217c6764546cada9769a621) for ‘first shuffle, then find the first valid one’ over ‘select the valid ones, then find a random one’ – in my case the ‘shuffle + find’ approach is ~75 times faster than ‘select + sample’."},"comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments/100546941","html_url":"https://github.com/bbatsov/rubocop/pull/1871#issuecomment-100546941","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1871","id":100546941,"user":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"created_at":"2015-05-09T21:07:28Z","updated_at":"2015-05-09T21:07:28Z","body":"> Does it make sense to spec invocations on both a literal Array and a variable? I think this is a bit much, especially given that the cop does not check the target of the #shuffle call…\r\n\r\nYeah, the array examples are redundant.\r\n\r\n> Does it make sense to spec that the cop both does not register an offence for and does not auto-correct the same acceptable cases? It seems auto-correction does not kick in when there are no offences to begin with…\r\n\r\nYep, if there are no offenses auto-correction does nothing. No need for such tests."}}