When naming an extension on some type A that retur...
# getting-started
e
When naming an extension on some type A that returns a type B, what are the conventional names for such functions? For example, there are •
fun <T> Array<out T>.asList(): List<T>
fun <T> Array<out T>.toList(): List<T>
By signature, they are identical. So the behaviour must define the naming difference. Likewise, there exists a
fun <T> Array<out T>.asIterable(): Iterable<T>
but not
toIterable
. Then there are all kinds of variants that use names like
mapTo
. When do you use
as
,
to
,
mapTo
or something else?
d
as
- is just a cheap cast/view.
to
- is a conversion.
e
I see, thanks
So in a non-collection/iterable context, e.g. domain models, how would you name a function that converts a network model to a database/business logic model?
fun NetworkType.toDatabaseType(): DatabaseType
👌 3
🙏