{"action":"created","issue":{"url":"https://api.github.com/repos/ramda/ramda/issues/848","labels_url":"https://api.github.com/repos/ramda/ramda/issues/848/labels{/name}","comments_url":"https://api.github.com/repos/ramda/ramda/issues/848/comments","events_url":"https://api.github.com/repos/ramda/ramda/issues/848/events","html_url":"https://github.com/ramda/ramda/issues/848","id":59348586,"number":848,"title":"R.propOr not as useful as lodash's _.result; should it throw if object is undefined?","user":{"login":"Andrew-Webb","id":3470891,"avatar_url":"https://avatars.githubusercontent.com/u/3470891?v=3","gravatar_id":"","url":"https://api.github.com/users/Andrew-Webb","html_url":"https://github.com/Andrew-Webb","followers_url":"https://api.github.com/users/Andrew-Webb/followers","following_url":"https://api.github.com/users/Andrew-Webb/following{/other_user}","gists_url":"https://api.github.com/users/Andrew-Webb/gists{/gist_id}","starred_url":"https://api.github.com/users/Andrew-Webb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andrew-Webb/subscriptions","organizations_url":"https://api.github.com/users/Andrew-Webb/orgs","repos_url":"https://api.github.com/users/Andrew-Webb/repos","events_url":"https://api.github.com/users/Andrew-Webb/events{/privacy}","received_events_url":"https://api.github.com/users/Andrew-Webb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-28T16:59:09Z","updated_at":"2015-03-01T16:09:35Z","closed_at":null,"body":"This is nice in lodash:-\r\n\r\n        var people = [\r\n            {\r\n                name: \"Dave\",\r\n                age: 30\r\n            },\r\n            {\r\n                name: \"Anne\",\r\n                age: 28\r\n            },\r\n        ];\r\n\r\n        _.result(_.find(people, function (person) {\r\n            return person.age === 40;\r\n        }), \"name\", undefined);\r\n\r\nDepending on the result of the `person.age === N` test, either the name of the person or undefined will be returned.\r\n\r\nThe Ramda equivalent using propOr (is there a better way?) isn't useful:-\r\n\r\n        R.propOr(undefined, \"name\", R.find(R.propEq('age', 40))(people));\r\n\r\nThis throws with \"Uncaught TypeError: Cannot convert undefined or null to object\".\r\n\r\nWhat makes the lodash function work is the fact that _.result can cope with the result of the find being undefined (or null).  R.propOr can't cope with this.  I think that it (and similar functions) should be able to cope with undefineds and nulls - especially since the result of many list functions (returning undefined) might well be piped into them.\r\n\r\n(Yes, I've got the first two args to R.propOr the right way round.  The documentation has it wrong; I've raised a separate issue about that.)\r\n"},"comment":{"url":"https://api.github.com/repos/ramda/ramda/issues/comments/76604548","html_url":"https://github.com/ramda/ramda/issues/848#issuecomment-76604548","issue_url":"https://api.github.com/repos/ramda/ramda/issues/848","id":76604548,"user":{"login":"CrossEye","id":151263,"avatar_url":"https://avatars.githubusercontent.com/u/151263?v=3","gravatar_id":"","url":"https://api.github.com/users/CrossEye","html_url":"https://github.com/CrossEye","followers_url":"https://api.github.com/users/CrossEye/followers","following_url":"https://api.github.com/users/CrossEye/following{/other_user}","gists_url":"https://api.github.com/users/CrossEye/gists{/gist_id}","starred_url":"https://api.github.com/users/CrossEye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CrossEye/subscriptions","organizations_url":"https://api.github.com/users/CrossEye/orgs","repos_url":"https://api.github.com/users/CrossEye/repos","events_url":"https://api.github.com/users/CrossEye/events{/privacy}","received_events_url":"https://api.github.com/users/CrossEye/received_events","type":"User","site_admin":false},"created_at":"2015-03-01T16:09:35Z","updated_at":"2015-03-01T16:09:35Z","body":"Also note, the documentation now lives at http://ramdajs.com/docs/\r\n"}}