|
|
|
|
|
by chrismorgan
1652 days ago
|
|
It only looks messy. It’s not particularly difficult to read, and with what it’s expressing there’s really no way of expressing it in shorter terms. “A method on an Option[T] named Map, generic over type U, taking one argument, a function from a T to a U, and returning an Option[U].” Mind you, I wouldn’t mind colons and arrows as separators which I think make it easier to read; here’s what it’d look like in a somewhat more Rust-like syntax: fn Map<U: any>(self: Option<T>, f: fn(a: T) -> U) -> Option<U> { ... }
I would also note that signatures like these are mostly found in foundational types; they take a bit more effort and practice to write, but you don’t often have to do so; and have the outcome that the API is more pleasant to use—no more interface objects and downcasting everywhere, in Go terms. |
|
Concerning resulting API: isn't code generation solves a problem with interface objects and downcasting?