{"action":"created","issue":{"url":"https://api.github.com/repos/rakudo/rakudo/issues/1661","repository_url":"https://api.github.com/repos/rakudo/rakudo","labels_url":"https://api.github.com/repos/rakudo/rakudo/issues/1661/labels{/name}","comments_url":"https://api.github.com/repos/rakudo/rakudo/issues/1661/comments","events_url":"https://api.github.com/repos/rakudo/rakudo/issues/1661/events","html_url":"https://github.com/rakudo/rakudo/issues/1661","id":309135677,"number":1661,"title":"Remove .grep with .count > 1 Callables","user":{"login":"zoffixznet","id":5747918,"avatar_url":"https://avatars2.githubusercontent.com/u/5747918?v=4","gravatar_id":"","url":"https://api.github.com/users/zoffixznet","html_url":"https://github.com/zoffixznet","followers_url":"https://api.github.com/users/zoffixznet/followers","following_url":"https://api.github.com/users/zoffixznet/following{/other_user}","gists_url":"https://api.github.com/users/zoffixznet/gists{/gist_id}","starred_url":"https://api.github.com/users/zoffixznet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoffixznet/subscriptions","organizations_url":"https://api.github.com/users/zoffixznet/orgs","repos_url":"https://api.github.com/users/zoffixznet/repos","events_url":"https://api.github.com/users/zoffixznet/events{/privacy}","received_events_url":"https://api.github.com/users/zoffixznet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-27T21:12:07Z","updated_at":"2018-03-27T21:26:42Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"This was first brought up as an example in https://github.com/rakudo/rakudo/issues/1657\r\n\r\n`.grep` has an undocumented feature where you can give it a Callable with `.count > 2`:\r\n\r\n```\r\n<Zoffix__> m: dd (3, 1, 2).kv.grep: { $^a == $^b }\r\n<camelia> rakudo-moar 637147af4: OUTPUT: «((1, 1), (2, 2)).Seq␤»\r\n```\r\n\r\nThis behavious is baffling to me, as `.grep` is supposed to be a means to **filter** the data, yet in this special case it also mutates it. \r\n\r\nThe way it behave at the moment isn't how I would've expected it to consume the original data, so there's also an issue of producing some arcane, unintuitive behaviour.\r\n\r\nThe alternative for the same output is rather straightforward and is only 4-characters longer:\r\n\r\n```\r\n<Zoffix__> m: dd (3, 1, 2).kv.rotor(2).grep: { [==] $_  }\r\n<camelia> rakudo-moar 637147af4: OUTPUT: «((1, 1), (2, 2)).Seq␤»\r\n```\r\n\r\nIn addition, there's a `.map` alternative as well:\r\n\r\n```\r\n<Zoffix__> m: dd (3, 1, 2).kv.map: { $^a == $^b or next; ($a, $b) }\r\n<camelia> rakudo-moar 637147af4: OUTPUT: «((1, 1), (2, 2)).Seq␤»\r\n```\r\n\r\nLastly, I see exactly one test in 6.c roast for this behaviour:\r\n\r\n```\r\nmy @in = ( 1, 1, 2, 3, 4, 4 );\r\nis (grep { $^a == $^b }, @in), (1, 1, 4, 4), 'grep takes two at a time';\r\n```\r\n\r\nYou may notice the resultant output isn't actually structured to how the author expected the output to\r\nbe produced. The reason the test passes at all is because of inappropriate test function `is` being used. `is` stringifies its arguments and destroys all structure.\r\n\r\n----------\r\n\r\nTo summarize, my reasons for removal of this feature are:\r\n\r\n* It's a special case of .grep that mutates original stream of data by `.rotor`ing it. No other arguments do this.\r\n* It's confusing behaviour, as the mutation of original data happens behind the scenes\r\n* It's easy to replicate this uncommonly-wanted behaviour with explicit `.rotor` or a map call.\r\n* The only spec test covering this behaviour is passing for the wrong reason and the current behaviour doesn't match what the original designer expected this feature to behave as.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rakudo/rakudo/issues/comments/376681180","html_url":"https://github.com/rakudo/rakudo/issues/1661#issuecomment-376681180","issue_url":"https://api.github.com/repos/rakudo/rakudo/issues/1661","id":376681180,"user":{"login":"zoffixznet","id":5747918,"avatar_url":"https://avatars2.githubusercontent.com/u/5747918?v=4","gravatar_id":"","url":"https://api.github.com/users/zoffixznet","html_url":"https://github.com/zoffixznet","followers_url":"https://api.github.com/users/zoffixznet/followers","following_url":"https://api.github.com/users/zoffixznet/following{/other_user}","gists_url":"https://api.github.com/users/zoffixznet/gists{/gist_id}","starred_url":"https://api.github.com/users/zoffixznet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoffixznet/subscriptions","organizations_url":"https://api.github.com/users/zoffixznet/orgs","repos_url":"https://api.github.com/users/zoffixznet/repos","events_url":"https://api.github.com/users/zoffixznet/events{/privacy}","received_events_url":"https://api.github.com/users/zoffixznet/received_events","type":"User","site_admin":false},"created_at":"2018-03-27T21:26:42Z","updated_at":"2018-03-27T21:26:42Z","author_association":"CONTRIBUTOR","body":"And 1 more argument for its removal. It's currently broken for all but `:v` versions of grep. So seems it was added to roast as an afterthought, pre-GLR and the roasted test is passing for the wrong reason.\r\n\r\n```\r\n<Zoffix__> m: <a b c>.kv.grep(-> $, $ { True }, :kv).say\r\n<camelia> rakudo-moar e31dd966f: OUTPUT: «Too few positionals passed; expected 2 arguments but got 1␤  in block <unit> at <tmp> line 1␤␤»\r\n<Zoffix__> m: <a b c>.kv.grep(-> $, $ { True }, :k).say\r\n<camelia> rakudo-moar e31dd966f: OUTPUT: «Too few positionals passed; expected 2 arguments but got 1␤  in block <unit> at <tmp> line 1␤␤»\r\n<Zoffix__> m: <a b c>.kv.grep(-> $, $ { True }, :p).say\r\n<camelia> rakudo-moar e31dd966f: OUTPUT: «Too few positionals passed; expected 2 arguments but got 1␤  in block <unit> at <tmp> line 1␤␤»\r\n<Zoffix__> m: <a b c>.kv.grep(-> $, $ { True }, :v).say\r\n<camelia> rakudo-moar e31dd966f: OUTPUT: «((0 a) (1 b) (2 c))␤»\r\n```"}}
{"actor":{"display_login":"zoffixznet"}}