<https://viktor-sirotin.medium.com/kotunil-si-unit...
# datascience
a
Just for the record, there was a previous much more simple attempt here: https://github.com/nacular/measured
My main concern for this library is scope pollution. Wouldn't it be better to define a scope for those extensions? It would require context receivers for full flexibility, but since they are on the table, it makes sense to use it.
v
You are right. nacular/mesuared is relatively simple bibliotek. Requirements for KotUniL are much more extensive.
Could you please to explain your idea with receivers?
a
Another reason to use scopes is the same reason we use algebra scopes in KMarth - the treatment of units is slightly different in different domains. I use different type-safe units in different projects.
The idea is that you define your extensions not globally like
Number.m
, but inside specific scope like
context(TypeSafeUnitsScope) Number.m
. You can do it without context receivers by creating member extensions for the object or class, but it will limit extensibility. because you will have to extend class to add new units. Context receivers solve this problem.
v
To be honest, I believe, that context receivers should be used in very special, very rare domains. The possible problem of scope popylation by using of KotUniL can be solved with intelligently using of imports, IMHO. Nevertheless, thank you for your suggestion. I will think about it further.