{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/2578","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/2578/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/2578/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/2578/events","html_url":"https://github.com/dotnet/corefx/issues/2578","id":98411423,"number":2578,"title":"API Addition: Add Lazy<T>(T value) constructor that just takes the value","user":{"login":"justinvp","id":710598,"avatar_url":"https://avatars.githubusercontent.com/u/710598?v=3","gravatar_id":"","url":"https://api.github.com/users/justinvp","html_url":"https://github.com/justinvp","followers_url":"https://api.github.com/users/justinvp/followers","following_url":"https://api.github.com/users/justinvp/following{/other_user}","gists_url":"https://api.github.com/users/justinvp/gists{/gist_id}","starred_url":"https://api.github.com/users/justinvp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinvp/subscriptions","organizations_url":"https://api.github.com/users/justinvp/orgs","repos_url":"https://api.github.com/users/justinvp/repos","events_url":"https://api.github.com/users/justinvp/events{/privacy}","received_events_url":"https://api.github.com/users/justinvp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-31T15:14:55Z","updated_at":"2015-07-31T15:14:55Z","closed_at":null,"body":"Consider adding a constructor to `Lazy<T>`, e.g. `public Lazy(T value)`, for cases where the value is already available but still needs to be wrapped in a `Lazy<T>` instance to match other uses.\r\n\r\n## Rationale\r\n\r\nThere are situations where a value is already available but still needs to be wrapped in a `Lazy<T>`, e.g.:\r\n\r\n```c#\r\nstring value = ...;\r\nLazy<string> lazy = new Lazy<string>(() => value);\r\n```\r\n\r\nUnfortunately, this requires two allocations: one for the `Func<string>` delegate and another for the closure around `value`.\r\n\r\nA new constructor on `Lazy<T>` that takes just the value would avoid these unnecessary delegate and closure allocations, e.g.:\r\n\r\n```c#\r\nstring value = ...;\r\nLazy<string> lazy = new Lazy<string>(value);\r\n```\r\n\r\n## Proposed API\r\n\r\n```c#\r\npublic class Lazy<T>\r\n{\r\n    // Proposed\r\n    public Lazy(T value);\r\n\r\n    // Existing\r\n    public Lazy();\r\n    public Lazy(bool isThreadSafe);\r\n    public Lazy(LazyThreadSafetyMode mode);\r\n    public Lazy(Func<T> valueFactory);\r\n    public Lazy(Func<T> valueFactory, bool isThreadSafe);\r\n    public Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode)\r\n\r\n    ...\r\n}\r\n```"}}