Settings

Theme

Making a Numeric Type in Swift

fabiancanas.com

12 points by fcanas · 2 comments

Reader

1 thread
Someone

Improvement: add multiplications "double times T" and "T times double" and division "T divided by double", all returning T.

That allows you Tom for example, compute how far a return journey to a city at Distance d is.

  • fcanasOP

    There are many ways to continue to extend the `Distance` type, and many other types that can be constructed in the same fashion. Each extension should be considered in the context of the code base it's going to operate in. For example, it's not difficult to create a new protocol, some generic functions with type constraints, and end up with an `Area` type with a fully correct relationship to `Distance`. I may write about such extensions as I continue to explore this space.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection