Hi all, I'm trying to refactor some code, and I feel like I'm almost there, but I can't find the last missing bit. I have the following code:
MemberTbl.select {
MemberTbl.member_id eq "200"
}.first().also {
assertThat(it[MemberTbl.id]).isEqualTo("200")
}
But, I'd like to refactor it to something like:
MemberTbl.findByMemberId("200")
with the help of an extension function, since this code is duplicated quite a lot.
What I have so far is this:
private fun MemberTbl.findByMemberId(s: String, row: ResultRow.() -> Unit) = this.select { member_id eq s }.first().also { row (it) }
So that my end result will look like this:
MemberTbl.findByMemberId("200") {
assertThat(it[MemberTbl.id]).isEqualTo("200")
}
But that won't, since the
it
in the assertEquals is no longer the closure passed in. How can I fix this?