{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/Argo/issues/113","labels_url":"https://api.github.com/repos/thoughtbot/Argo/issues/113/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/Argo/issues/113/comments","events_url":"https://api.github.com/repos/thoughtbot/Argo/issues/113/events","html_url":"https://github.com/thoughtbot/Argo/issues/113","id":69236233,"number":113,"title":"Converting types when decoding","user":{"login":"marcelofabri","id":833072,"avatar_url":"https://avatars.githubusercontent.com/u/833072?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelofabri","html_url":"https://github.com/marcelofabri","followers_url":"https://api.github.com/users/marcelofabri/followers","following_url":"https://api.github.com/users/marcelofabri/following{/other_user}","gists_url":"https://api.github.com/users/marcelofabri/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelofabri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelofabri/subscriptions","organizations_url":"https://api.github.com/users/marcelofabri/orgs","repos_url":"https://api.github.com/users/marcelofabri/repos","events_url":"https://api.github.com/users/marcelofabri/events{/privacy}","received_events_url":"https://api.github.com/users/marcelofabri/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-17T23:14:57Z","updated_at":"2015-05-24T01:49:51Z","closed_at":null,"body":"Hi guys,\r\n\r\nI'm trying to use Argo and convert a String to NSURL inside the `decode` method. I thought that using flatMap (`>>-`) was enough, but this way the compiler just hangs:\r\n\r\n```swift\r\nstruct JSONParseUtils {\r\n    static func parseURL(URLString: String) -> NSURL? {\r\n        return NSURL(string: URLString)\r\n    }\r\n}\r\n\r\npublic struct ImagesURLs {\r\n    public let fullImageURL: NSURL?\r\n    public let mediumImageURL: NSURL?\r\n    public let thumbImageURL: NSURL?\r\n}\r\n\r\nextension ImagesURLs: JSONDecodable {\r\n    static func create(fullImageURL: NSURL?)(mediumImageURL: NSURL?)(thumbImageURL: NSURL?) -> ImagesURLs {\r\n        return ImagesURLs(fullImageURL: fullImageURL, mediumImageURL: mediumImageURL, thumbImageURL: thumbImageURL)\r\n    }\r\n    \r\n    public static func decode(j: JSONValue) -> ImagesURLs? {\r\n        return ImagesURLs.create\r\n            <^> j <|? \"full\"  >>- JSONParseUtils.parseURL\r\n            <*> j <|? \"medium\" >>- JSONParseUtils.parseURL\r\n            <*> j <|? \"thumb\" >>- JSONParseUtils.parseURL\r\n    }\r\n}\r\n```\r\n\r\nChanging `parseURL` to receive an `String?` (and adapting it) works, but once a field is `nil` in a JSON, `decode` returns `nil` (it should continue evaluating).\r\n\r\n**NOTE**: I solved this by creating an extension on `NSURL` that conforms to `JSONDecodable`, but sometimes this may not be possible. For example: I could want to create an `NSDate` and have two possible formats (e.g. UNIX timestamp and ISO-8601).\r\n\r\nAlso, it'd be great to include this kind of example on README or some other place."},"comment":{"url":"https://api.github.com/repos/thoughtbot/Argo/issues/comments/104966709","html_url":"https://github.com/thoughtbot/Argo/issues/113#issuecomment-104966709","issue_url":"https://api.github.com/repos/thoughtbot/Argo/issues/113","id":104966709,"user":{"login":"marcelofabri","id":833072,"avatar_url":"https://avatars.githubusercontent.com/u/833072?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelofabri","html_url":"https://github.com/marcelofabri","followers_url":"https://api.github.com/users/marcelofabri/followers","following_url":"https://api.github.com/users/marcelofabri/following{/other_user}","gists_url":"https://api.github.com/users/marcelofabri/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelofabri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelofabri/subscriptions","organizations_url":"https://api.github.com/users/marcelofabri/orgs","repos_url":"https://api.github.com/users/marcelofabri/repos","events_url":"https://api.github.com/users/marcelofabri/events{/privacy}","received_events_url":"https://api.github.com/users/marcelofabri/received_events","type":"User","site_admin":false},"created_at":"2015-05-24T01:49:51Z","updated_at":"2015-05-24T01:49:51Z","body":"I justed tested this, but I couldn't make it work:\r\n\r\n```swift\r\nstruct JSONParseUtils {\r\n    static func parseURL(URLString: String?) -> NSURL? {\r\n        return flatMap(URLString) { NSURL(string: $0) }\r\n    }\r\n}\r\n\r\n\r\nextension ImagesURLs: Decodable {\r\n    static func create(fullImageURL: NSURL?)(mediumImageURL: NSURL?)(thumbImageURL: NSURL?) -> ImagesURLs {\r\n        return ImagesURLs(fullImageURL: fullImageURL, mediumImageURL: mediumImageURL, thumbImageURL: thumbImageURL)\r\n    }\r\n    \r\n    public static func decode(j: JSON) -> Decoded<ImagesURLs> {\r\n        return ImagesURLs.create\r\n            <^> pure((j <| \"full\") >>- JSONParseUtils.parseURL)\r\n            <*> pure((j <| \"medium\") >>- JSONParseUtils.parseURL)\r\n            <*> pure((j <| \"thumb\") >>- JSONParseUtils.parseURL)\r\n    }\r\n}\r\n```\r\n\r\nThe compiler just gives up: \r\n\r\n> Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions\r\n\r\nI also didn't understand why you suggested `<|` and not `<|?`."}}