Let's say I want a collection, a deferred or whate...
# announcements
c
Let's say I want a collection, a deferred or whatever, of 2 types. Do you recommend:
Copy code
//1
Something<Pair<A, B>>
Copy code
//2
data class Other<A, B>(...)
Something<Other<A, B>>
Copy code
//3
typealias Other<A, B> = Pair<A, B>
Something<Other<A, B>>
I'm expecting that the answer is "it depends", what are some good examples to choose which one to use?
d
Only use
Pair
unless: * You intend to access the fields not by decomposition frequently. * At least one of your type arguments is a concrete type and the compound type is used a lot in your code * You have special functionality for the type (such as member functions) * Your code is performance sensitive and you want to store primitive types in the compound
If any of the conditions are true, just make a data class in one line of code.
I don't recommend using typealias very much at all
Typealias is sadly a pretty underwhelming language feature at the moment
It can be very useful don't get me wrong
But not that useful. Often times I would use an interface with a function instead of a lambda type if I want to name it, for example.