{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/22324","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/22324/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/22324/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/22324/events","html_url":"https://github.com/JuliaLang/julia/pull/22324","id":235006459,"number":22324,"title":"add replace & replace! for collections","user":{"login":"rfourquet","id":8462914,"avatar_url":"https://avatars2.githubusercontent.com/u/8462914?v=3","gravatar_id":"","url":"https://api.github.com/users/rfourquet","html_url":"https://github.com/rfourquet","followers_url":"https://api.github.com/users/rfourquet/followers","following_url":"https://api.github.com/users/rfourquet/following{/other_user}","gists_url":"https://api.github.com/users/rfourquet/gists{/gist_id}","starred_url":"https://api.github.com/users/rfourquet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rfourquet/subscriptions","organizations_url":"https://api.github.com/users/rfourquet/orgs","repos_url":"https://api.github.com/users/rfourquet/repos","events_url":"https://api.github.com/users/rfourquet/events{/privacy}","received_events_url":"https://api.github.com/users/rfourquet/received_events","type":"User","site_admin":false},"labels":[{"id":522769435,"url":"https://api.github.com/repos/JuliaLang/julia/labels/collections","name":"collections","color":"09aeb1","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-06-10T14:39:09Z","updated_at":"2017-06-18T10:52:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/22324","html_url":"https://github.com/JuliaLang/julia/pull/22324","diff_url":"https://github.com/JuliaLang/julia/pull/22324.diff","patch_url":"https://github.com/JuliaLang/julia/pull/22324.patch"},"body":"This adds methods to `replace` for `AbstractArray`, `AbstractSet` and `Associative` and a corresponding inplace `replace!` function.\r\nDid I miss already existing similar functionality in Base?\r\n\r\nThe order in which to put the 2 function arguments `pred` and `f` can be discussed.\r\n\r\nAlso, `replace!(f::Function, A, old)` is not included as it would be ambiguous with `replace!(pred, A, new)` (and a new function name would be necessary, e.g. `replaceif!`); But it is assumed that in most of the cases, the replacement value `f(x)` can be computed by `f(old)` and then use `replace!(A, old, f(old))`. Otherwise, `replace!(pred, f, A)` can be used.\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/309270096","html_url":"https://github.com/JuliaLang/julia/pull/22324#issuecomment-309270096","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/22324","id":309270096,"user":{"login":"nalimilan","id":1120448,"avatar_url":"https://avatars0.githubusercontent.com/u/1120448?v=3","gravatar_id":"","url":"https://api.github.com/users/nalimilan","html_url":"https://github.com/nalimilan","followers_url":"https://api.github.com/users/nalimilan/followers","following_url":"https://api.github.com/users/nalimilan/following{/other_user}","gists_url":"https://api.github.com/users/nalimilan/gists{/gist_id}","starred_url":"https://api.github.com/users/nalimilan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nalimilan/subscriptions","organizations_url":"https://api.github.com/users/nalimilan/orgs","repos_url":"https://api.github.com/users/nalimilan/repos","events_url":"https://api.github.com/users/nalimilan/events{/privacy}","received_events_url":"https://api.github.com/users/nalimilan/received_events","type":"User","site_admin":false},"created_at":"2017-06-18T10:52:19Z","updated_at":"2017-06-18T10:52:19Z","body":"> I think I addressed all the comments. I still have to know how to set the link to replace from the doc of replace! point to the collection version, not to the string version; and to not have a duplicate docstring for the collection version...\r\n\r\nCan you elaborate? I think generally we point the docstring to the *function*, which concatenates docstrings for all methods. That's not ideal, but at least it includes the expected docstring.\r\n\r\n> On the design level:\r\n> \r\n>     I think @nalimilan's example of using replace(A, old=>new) is interesting; but Allowing multiple pairs would not be compatible with a \"count\" argument (n): replace(A, p::Pair..., n=typemax(Int)) is not valid... As using a Dict of those pairs internally would probably be necessary for efficiency, it could be required to pass a Dict directly instead: replace(A, repl::Dict, n=typemax(Int)).\r\n\r\nActually, no, the pairs should be passed as a varargs so that the compiler is able to unroll the checks rather than using a loop. With a small number of pairs, a dict isn't faster than repeated equality tests.\r\n\r\nBut you're right that the handling of `n` would be problematic in that case. We could make it a keyword argument. I guess it really depends on whether we want to make `replace` very general or rather keep it as simple as possible.\r\n\r\n>     there are two forms when a predicate is given:\r\n> \r\n> replace(pred, A, new, [n])\r\n> replace(pred, f::Callable, A, [n])\r\n> \r\n> It would be cleaner to have instead replace(pred, A, f::Callable, [n]) for the second, to keep the same argument order, but this would collide when A can store callables... Do we care enough for this case? (I guess yes)\r\n\r\nYes, that's a tough call. The API based on pairs would solve this."}}
{"actor":{"display_login":"nalimilan"}}