{"action":"created","issue":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/84","repository_url":"https://api.github.com/repos/gcanti/tcomb","labels_url":"https://api.github.com/repos/gcanti/tcomb/issues/84/labels{/name}","comments_url":"https://api.github.com/repos/gcanti/tcomb/issues/84/comments","events_url":"https://api.github.com/repos/gcanti/tcomb/issues/84/events","html_url":"https://github.com/gcanti/tcomb/issues/84","id":53506542,"number":84,"title":"t.func should handle optional arguments?","user":{"login":"gcanti","id":878912,"avatar_url":"https://avatars2.githubusercontent.com/u/878912?v=3","gravatar_id":"","url":"https://api.github.com/users/gcanti","html_url":"https://github.com/gcanti","followers_url":"https://api.github.com/users/gcanti/followers","following_url":"https://api.github.com/users/gcanti/following{/other_user}","gists_url":"https://api.github.com/users/gcanti/gists{/gist_id}","starred_url":"https://api.github.com/users/gcanti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gcanti/subscriptions","organizations_url":"https://api.github.com/users/gcanti/orgs","repos_url":"https://api.github.com/users/gcanti/repos","events_url":"https://api.github.com/users/gcanti/events{/privacy}","received_events_url":"https://api.github.com/users/gcanti/received_events","type":"User","site_admin":false},"labels":[{"id":109211692,"url":"https://api.github.com/repos/gcanti/tcomb/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2015-01-06T11:38:27Z","updated_at":"2017-04-27T21:33:19Z","closed_at":"2015-05-07T08:18:30Z","body":"An example:\n\n``` js\nvar t = require('tcomb');\n\nvar addWithMessage = t.func([t.Num, t.Num, t.maybe(t.Str)], t.Num).of(\n    function(num1, num2, optionalMessage) {\n        if (optionalMessage) {\n            console.log(optionalMessage);\n        }\n        return num1 + num2;\n    }\n);\n\nconsole.log(addWithMessage(1, 2)); // => returns a function (since the auto curry is in place), should execute the function instead?\n```\n\ncc @beckyconning \n"},"comment":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/comments/297845485","html_url":"https://github.com/gcanti/tcomb/issues/84#issuecomment-297845485","issue_url":"https://api.github.com/repos/gcanti/tcomb/issues/84","id":297845485,"user":{"login":"fernandocanizo","id":1643948,"avatar_url":"https://avatars0.githubusercontent.com/u/1643948?v=3","gravatar_id":"","url":"https://api.github.com/users/fernandocanizo","html_url":"https://github.com/fernandocanizo","followers_url":"https://api.github.com/users/fernandocanizo/followers","following_url":"https://api.github.com/users/fernandocanizo/following{/other_user}","gists_url":"https://api.github.com/users/fernandocanizo/gists{/gist_id}","starred_url":"https://api.github.com/users/fernandocanizo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fernandocanizo/subscriptions","organizations_url":"https://api.github.com/users/fernandocanizo/orgs","repos_url":"https://api.github.com/users/fernandocanizo/repos","events_url":"https://api.github.com/users/fernandocanizo/events{/privacy}","received_events_url":"https://api.github.com/users/fernandocanizo/received_events","type":"User","site_admin":false},"created_at":"2017-04-27T21:33:19Z","updated_at":"2017-04-27T21:33:19Z","body":"Sorry, I'm new to tcomb and I thought `t.maybe` combinator could be used directly. Now I see that I need to build a new type first, so I tried:\r\n\r\n```\r\nvar OptionalNumber = t.maybe(t.Number, 'OptionalNumber')\r\nvar SumType = t.func([t.Number, OptionalNumber], t.Number)\r\nvar sum = SumType.of((a, b) => a + b)\r\nsum(1)\r\nTypeError: [tcomb] Invalid value null supplied to Number\r\n```\r\n\r\nI see that if for instance I define sum like:\r\n\r\n```\r\nvar sum = SumType.of((a, b) => b ? a + b : a)\r\n// Then I can perfectly `sum` a single paramenter:\r\nsum(1) // 1\r\n```\r\nBut now I'm checking for `b`, what's the point of using tcomb?\r\n\r\nWell, I understand it covers other cases, but I think it should cover this one too.\r\n\r\nWhat am I missing?\r\n\r\nExtra questions:\r\n\r\nIs like I'm assuming and one cannot use `t.maybe` combinator directly on a `t.func` definiton? Or is it that I've used it wrong in my examples? (I'm referring in particular to this now:\r\n```\r\nvar SumType = t.func([t.Number, t.maybe(t.Number)], t.Number)\r\nvar sum = SumType.of((a, b) => a + b)\r\nsum(1)\r\nTypeError: [tcomb] Invalid value null supplied to Number\r\n```\r\n\r\nBy directly I mean: without defining a new type first.\r\n\r\nAnother consideration: doesn't it get too verbose? Imagine we would need optional values for every type, then there's a lot of types to type.\r\n\r\nI hope someone can shed some light on this."}}
{"actor":{"display_login":"fernandocanizo"}}