{"action":"opened","issue":{"url":"https://api.github.com/repos/date-fns/date-fns/issues/545","repository_url":"https://api.github.com/repos/date-fns/date-fns","labels_url":"https://api.github.com/repos/date-fns/date-fns/issues/545/labels{/name}","comments_url":"https://api.github.com/repos/date-fns/date-fns/issues/545/comments","events_url":"https://api.github.com/repos/date-fns/date-fns/issues/545/events","html_url":"https://github.com/date-fns/date-fns/issues/545","id":253199383,"number":545,"title":"Parameter ordering is backwards","user":{"login":"chasm","id":29755,"avatar_url":"https://avatars2.githubusercontent.com/u/29755?v=4","gravatar_id":"","url":"https://api.github.com/users/chasm","html_url":"https://github.com/chasm","followers_url":"https://api.github.com/users/chasm/followers","following_url":"https://api.github.com/users/chasm/following{/other_user}","gists_url":"https://api.github.com/users/chasm/gists{/gist_id}","starred_url":"https://api.github.com/users/chasm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chasm/subscriptions","organizations_url":"https://api.github.com/users/chasm/orgs","repos_url":"https://api.github.com/users/chasm/repos","events_url":"https://api.github.com/users/chasm/events{/privacy}","received_events_url":"https://api.github.com/users/chasm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-28T00:02:05Z","updated_at":"2017-08-28T00:02:05Z","closed_at":null,"body":"Proper parameter ordering and currying is essential to composability.\r\n\r\nHere is an example of a typical date-fns function from the v2 docs:\r\n\r\n```js\r\nformat(date, format, [options])\r\n```\r\n\r\nThis is backwards. The `format` and the `options` will almost certainly be set infrequently. With this ordering, I have to pass them _every time_.\r\n\r\nThe proper FP ordering for the arguments puts the date last and curries the function:\r\n\r\n```js\r\nformat(format, options, date)\r\n```\r\n\r\nThat allows me to do this:\r\n\r\n```js\r\nconst myFormat = format('DD/MM/YYY', {})\r\n```\r\n\r\nWhich returns a function that takes only a date and formats it according to the format and options I supplied. I can then use that function all over my code without having to pass the format and the options over and over again. I can also use that to compose new functions as it takes a single parameter.\r\n\r\nAn even better choice would be to combine the format and the options into a single parameter. This could be polymorphic, with a String interpreted as a format string and an Object interpreted as an options object, perhaps with a `format` key. Or just take an options object and put the format string in it.\r\n\r\nThe proper parameter ordering is observed in libraries such as Ramda and Sanctuary (or even Lodash/FP), and these would be much better examples upon which to base v2 of date-fns than the old, poorly-considered underscore or lodash. Otherwise, someone will no doubt fork date-fns to fix the problem. JavaScript hell, anyone?\r\n\r\nPlease consider making this change _before_ you release v2 with other breaking changes.\r\n\r\nAnd it's not just the `format` function."}}
{"actor":{"display_login":"chasm"}}