karelpeeters
09/16/2018, 12:35 PMthemishkun
09/16/2018, 12:47 PMComponent1<A>
, Component2<A, B> : Component1<A>
etc.karelpeeters
09/16/2018, 12:49 PMDico
09/16/2018, 12:58 PMinterface HasComponent1<out A> {
fun component1(): A
}
interface HasComponent2<out A, out B> : HasComponent1<A> {
fun component2(): B
}
... etc,
And these would be implemented by data classes implicitly?
I used the interface naming of HasComponent
as you can see, but it doesn't really matter either way.themishkun
09/16/2018, 1:04 PMDico
09/16/2018, 1:05 PMkarelpeeters
09/16/2018, 1:12 PMkarelpeeters
09/16/2018, 1:13 PMcomponentN
behaviour to be opt-in for data classes, like for data class Point(x: Int, y: Int)
it makes sense but less so for Person(adress: Adress, age: Int)
. But that's too late anyway.themishkun
09/16/2018, 1:16 PMDico
09/16/2018, 1:19 PMHasComponent2
for example to check if it's allowed with 2 variables, when it can also be a HasComponent3
or HasComponent4
. It would be weird. Anyway, it's not important. Just something small to consider for how the interfaces are implemented.themishkun
09/16/2018, 1:24 PMkarelpeeters
09/16/2018, 1:28 PMval (a, b) = list(1, 2, 3)
karelpeeters
09/16/2018, 1:28 PMthemishkun
09/16/2018, 1:29 PMDico
09/16/2018, 1:30 PMdata class Data(val a: Int, val b: Int, val c: Int)
fun test(data: Data) {
val (a, b) = data // no error
}
Dico
09/16/2018, 1:31 PMkarelpeeters
09/16/2018, 1:31 PMList
and `data class`es have componentN
function, no difference as far as the compiler is concerned.Dico
09/16/2018, 1:33 PMList
, componentN
function is defined up to component5
. Maybe a little low for an upper limit for the rest of HasComponent
types.karelpeeters
09/16/2018, 1:34 PMcomponentN
functions.Dico
09/16/2018, 1:34 PMcomponentN
functions are operators. I didn't know that.karelpeeters
09/16/2018, 1:35 PMAndreas Sinz
09/16/2018, 1:48 PMDico
09/16/2018, 1:49 PMDico
09/16/2018, 1:49 PMthemishkun
09/16/2018, 2:40 PMkarelpeeters
09/16/2018, 2:41 PMtodd.ginsberg
09/16/2018, 4:11 PMkarelpeeters
09/16/2018, 4:13 PMDico
09/16/2018, 4:20 PMthemishkun
09/16/2018, 4:25 PMComponentN
-s, I just referred to FunctionN current limit as some point to start evaluating. How did you choose this number when implementing FunctionN?todd.ginsberg
09/16/2018, 4:26 PMkarelpeeters
09/16/2018, 4:28 PMthemishkun
09/16/2018, 4:37 PMinline fun <A,B,C> Component2<A,B>.consumeBy(f: ((A,B) -> C)): C =
f(this.component1(), this.component2())
the usage is like with the spread operator for arrays: fun drawAt(x: Int, y: Int)
Point(1,2).consumeBy(::drawAt)
Dico
09/16/2018, 4:38 PMthemishkun
09/16/2018, 4:39 PMwhen (user) {
in User("johnDoe", any()) -> ...
in User(any(), 13) -> ...
else -> ....
}
You could think of that as Mockito matchers, if you never met pattern-matching beforethemishkun
09/16/2018, 4:40 PMkarelpeeters
09/16/2018, 4:41 PMin
to check each of the components, if contains
isn't defined? And what does any()
return here? Why are there User
objects here?themishkun
09/16/2018, 4:45 PMin (::User).pattern("johnDoe", any())
or any other syntactic trick that will make a Pattern
object and give it some matchers. I can create a gist for youthemishkun
09/16/2018, 5:09 PMkarelpeeters
09/16/2018, 5:20 PMany()
matches in a variable.Dico
09/16/2018, 6:33 PMequals
always returns true. However, that would violate equals contract, and it would have to be the LHS of the comparison. It should probably be a contextual keyword of some sort instead.
As for creating a Pattern
object, I guess that would be cached statically for when expressions? It might be better to just inline the comparisons.
Finally, what about:
in User(name = "mikhail")
This wouldn't be possible with the componentN
functions however, but it would make sense semantically.themishkun
09/16/2018, 8:34 PMvoddan
09/18/2018, 4:34 AMvoddan
09/18/2018, 4:41 AMvoddan
09/18/2018, 4:42 AM