{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1943","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1943/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1943/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1943/events","html_url":"https://github.com/dotnet/csharplang/issues/1943","id":371973556,"node_id":"MDU6SXNzdWUzNzE5NzM1NTY=","number":1943,"title":"Add funcof operator to convert a single-method method group to a Func/Action","user":{"login":"ymassad","id":5919125,"node_id":"MDQ6VXNlcjU5MTkxMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/5919125?v=4","gravatar_id":"","url":"https://api.github.com/users/ymassad","html_url":"https://github.com/ymassad","followers_url":"https://api.github.com/users/ymassad/followers","following_url":"https://api.github.com/users/ymassad/following{/other_user}","gists_url":"https://api.github.com/users/ymassad/gists{/gist_id}","starred_url":"https://api.github.com/users/ymassad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymassad/subscriptions","organizations_url":"https://api.github.com/users/ymassad/orgs","repos_url":"https://api.github.com/users/ymassad/repos","events_url":"https://api.github.com/users/ymassad/events{/privacy}","received_events_url":"https://api.github.com/users/ymassad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-19T14:08:13Z","updated_at":"2018-10-19T14:31:37Z","closed_at":null,"author_association":"NONE","body":"Example:\r\n\r\n```\r\nclass Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        var func = funcof(M);\r\n    }\r\n\r\n    static int M(string p) => p.Length;\r\n}\r\n```\r\n\r\nThe line that uses the `funcof` operator would be translated to something like:\r\n\r\n`var func = (Func<string, int>)M;`\r\n\r\nIf the following is implemented:\r\nhttps://github.com/dotnet/csharplang/issues/269\r\n\r\nThen the type of the func variable would also contain the parameter names correctly.\r\n\r\nThe main benefit of such proposal is to be able to treat methods in C# as functions that can then be manipulated (e.g. partially invoked) and passed to other methods. This will make functional programming in C# easier.\r\n\r\n### Generic Methods\r\n\r\nSupporting this proposal for non-generic method should be relatively easy.\r\n\r\nI think it would be great to have support also for generic methods. As far as I know, C# currently does not allow a variable type to be an open generic.\r\n\r\nFor example, given this:\r\n\r\n`static int M<T>(T p1, string p2) => 1;`\r\n\r\n`funcof(M)` will be of type `Func<T, string, int>`. C# currently does not support a variable to be of this type (open).\r\n\r\nIf this is possible then we can do something like:\r\n\r\n`var func = funcof(M).PartiallyInvoke(\"value for string\");`\r\n\r\nWhere `PartiallyInvoke` is a generic user defined method that has many overloads to support partially invoking functions of different number of parameters and different indexes of the parameter to be fixed.\r\n\r\n`func` in this case is of type `Func<T,int>`. I can invoke it now like this:\r\n\r\n`func(1)` (T is now int)\r\n\r\nor\r\n\r\n`func(1u)` (T is now uint)\r\n\r\nIn the example, the PartiallyInvoke method overload is defined like this:\r\n\r\n```\r\npublic static Func<TInput1, TOutput> PartiallyInvoke<TInput1, TInput2, TOutput>(\r\n    this Func<TInput1, TInput2, TOutput> func,\r\n    TInput2 input2)\r\n{\r\n    return input1 => func(input1, input2);\r\n}\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/431383202","html_url":"https://github.com/dotnet/csharplang/issues/1943#issuecomment-431383202","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1943","id":431383202,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTM4MzIwMg==","user":{"login":"ymassad","id":5919125,"node_id":"MDQ6VXNlcjU5MTkxMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/5919125?v=4","gravatar_id":"","url":"https://api.github.com/users/ymassad","html_url":"https://github.com/ymassad","followers_url":"https://api.github.com/users/ymassad/followers","following_url":"https://api.github.com/users/ymassad/following{/other_user}","gists_url":"https://api.github.com/users/ymassad/gists{/gist_id}","starred_url":"https://api.github.com/users/ymassad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymassad/subscriptions","organizations_url":"https://api.github.com/users/ymassad/orgs","repos_url":"https://api.github.com/users/ymassad/repos","events_url":"https://api.github.com/users/ymassad/events{/privacy}","received_events_url":"https://api.github.com/users/ymassad/received_events","type":"User","site_admin":false},"created_at":"2018-10-19T14:31:37Z","updated_at":"2018-10-19T14:31:37Z","author_association":"NONE","body":"@HaloFour ,\r\n\r\n> What do you propose that the type of func be here?\r\n\r\nIt is `Func<T, string, int>`\r\n\r\nI know that C# does not allow the generic type parameter to be open. I am suggesting to add support for this to C# (the CLR also?)\r\n\r\n> Which immediately falls apart when a function has more than one parameter of the same type\r\n\r\nBecause the function is of type `Func<T, string, int>` and we are passing a string. \r\nThe compiler would detect that we need the overload I specified in the first post (updated after I wrote the post).\r\n\r\nMaybe this feature should be implemented for non-generic methods first and then adapter to generic methods.\r\n\r\n"}}
{"actor":{"display_login":"ymassad"}}