Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using partial application as a way to solve side loaded JSON with immutable value objects
// Returning a function here, instead of a fully realized object
extension Company: Decodable {
static func decode(j: JSON) -> Decoded<[People] -> Company> {
return create
<^> j <| "id"
<*> j <| ["attributes", "name"]
}
}
func parse(j: JSON) -> Company? {
// "included" holds the related people for the company
let company = (j <| "data" >>- Company.decode) <*> j <|| "included"
return company.value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment