3 ms·
Great read! I'm going to steal that use of 'typealias' when defining a closure that uses @escaping. Those method definitions are always so messy looking, this
by _31 8y ago
Great read!
I'm going to steal that use of 'typealias' when defining a closure that uses @escaping. Those method definitions are always so messy looking, this really cleans it up.
- dep_b 8y agoType alias is a poor alternative for true primitive types. Like (pseudo code): primitive Dollar: Decimal // no mixing with euros primitive Meter: Double // no confusion with miles You can do the same in Swift with typealias _but_ it will happily accept you passing in Euro where Dollar is declared because they’re both Decimals. This doesn’t happen in languages like F#.
- slavapestov 8y agoYou can define a struct with a single field of type Double.
- dep_b 8y agoTrue. I think there was a Money cocoapod that used your trick. But you can’t do anything with them you would normally do with the base type unless you add a ton of logic. Also in F# you get the type Meter/Hour if you divide Meters by Hours. Which multiplied by an Hour value gives you the distance traveled at that speed in that time.