{"action":"created","issue":{"url":"https://api.github.com/repos/lstrojny/functional-php/issues/65","labels_url":"https://api.github.com/repos/lstrojny/functional-php/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/lstrojny/functional-php/issues/65/comments","events_url":"https://api.github.com/repos/lstrojny/functional-php/issues/65/events","html_url":"https://github.com/lstrojny/functional-php/issues/65","id":91261752,"number":65,"title":"Memoize as a high order function","user":{"login":"theUniC","id":318014,"avatar_url":"https://avatars.githubusercontent.com/u/318014?v=3","gravatar_id":"","url":"https://api.github.com/users/theUniC","html_url":"https://github.com/theUniC","followers_url":"https://api.github.com/users/theUniC/followers","following_url":"https://api.github.com/users/theUniC/following{/other_user}","gists_url":"https://api.github.com/users/theUniC/gists{/gist_id}","starred_url":"https://api.github.com/users/theUniC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theUniC/subscriptions","organizations_url":"https://api.github.com/users/theUniC/orgs","repos_url":"https://api.github.com/users/theUniC/repos","events_url":"https://api.github.com/users/theUniC/events{/privacy}","received_events_url":"https://api.github.com/users/theUniC/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-26T14:13:15Z","updated_at":"2015-06-30T09:50:38Z","closed_at":null,"body":"What do you think about transforming the ```memoize``` function into a high order function? I think it would become easier to use from the client perspective and it may simplify its internal implementation. I'm thinking of something like\r\n\r\n```php\r\nfunction memoize(callable $function, callable $hashGenerator = null) {\r\n    if (null === $hashGenerator) {\r\n        $hashGenerator = function(array $arguments) {\r\n            // ...\r\n        }\r\n    }\r\n\r\n    return function (...$arguments) use ($function, $hashGenerator) {\r\n        static $localCache = [];\r\n\r\n        $key = $hashGenerator($arguments);\r\n\r\n        if (!array_key_exists($key, $localCache)) {\r\n            $localCache[$key] = $callback(...$arguments);\r\n        }\r\n\r\n        return $localCache[$key];\r\n    };\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/lstrojny/functional-php/issues/comments/117101625","html_url":"https://github.com/lstrojny/functional-php/issues/65#issuecomment-117101625","issue_url":"https://api.github.com/repos/lstrojny/functional-php/issues/65","id":117101625,"user":{"login":"lstrojny","id":79707,"avatar_url":"https://avatars.githubusercontent.com/u/79707?v=3","gravatar_id":"","url":"https://api.github.com/users/lstrojny","html_url":"https://github.com/lstrojny","followers_url":"https://api.github.com/users/lstrojny/followers","following_url":"https://api.github.com/users/lstrojny/following{/other_user}","gists_url":"https://api.github.com/users/lstrojny/gists{/gist_id}","starred_url":"https://api.github.com/users/lstrojny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lstrojny/subscriptions","organizations_url":"https://api.github.com/users/lstrojny/orgs","repos_url":"https://api.github.com/users/lstrojny/repos","events_url":"https://api.github.com/users/lstrojny/events{/privacy}","received_events_url":"https://api.github.com/users/lstrojny/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T09:50:38Z","updated_at":"2015-06-30T09:50:38Z","body":"I agree, the higher order function is a very nice way. Now we just have find a way to keep BC somehow. Ideas welcome :)"}}