4 ms·
I'm somewhat surprised that the Swift Optional doesn't come with `orElseThrow` or `filter`. I mean, even the Java Optional has those combinators.
by Sharlin 8y ago
I'm somewhat surprised that the Swift Optional doesn't come with `orElseThrow` or `filter`. I mean, even the Java Optional has those combinators.
- dep_b 8y agofilter -> flatMap / compactMap without arguments orElseThrow is something you might need more often in Java, Swift handles optionals with if let / else checks or Result enums instead of functions that either result an object or throw an Exception. Throwing errors / exceptions is pretty rare in the language compared to the Java / C# world. Only when doing stuff like mapping JSON I set up try / throw trees because in the end I might not care about the Error at all and just discard it.
- stiGGG 8y agoAnd with Codable times of manually mapping JSON to objects are over, at least you have to deal with something sane.
- dep_b 8y agoI really needed stuff like snake_case support
- saagarjha 8y agoCodableKeys should let you handle this.
- bunnycorn 8y agohttps://developer.apple.com/documentation/foundation/jsonencoder/keyencodingstrategy/converttosnakecase https://developer.apple.com/documentation/foundation/jsonenc... Also, as already said, CodingKeys.
- dep_b 8y agoRight, I said needed, not need ;)