ribesg
04/20/2018, 10:07 PMcache.entries.removeAll {
val res = now - it.value.first > duration
if (res) <http://log.info|log.info>("Removing value in cache $name for key ${it.key}")
res
}
ribesg
04/20/2018, 10:08 PMribesg
04/20/2018, 10:14 PMorangy
orangy
removeAll
is a Java method, then SAM conversion will create instance each time (I think)ribesg
04/20/2018, 10:20 PMribesg
04/20/2018, 10:21 PMorangy
now
is what makes it create a captureorangy
ribesg
04/20/2018, 10:32 PMopen fun clear() {
val now = now
cache.entries.removeAll {
val res = now - it.value.first > duration
if (res) <http://log.info|log.info>("Removing value in cache $name for key ${it.key}")
res
}
errors.entries.removeAll {
val res = now - it.value.first > errorDuration
if (res) <http://log.info|log.info>("Removing error in cache $name for key ${it.key}")
res
}
}
ribesg
04/20/2018, 10:33 PMorangy
clear
should create just two instances of lambdasribesg
04/20/2018, 10:51 PMorangy
now
into a local variable and use it in lambdas. They have to create an instance and capture value in an anonymous class so it is available to the code inside lambda.orangy
AnonymousClass(val now) : Predicate<Boolean> { override fun invoke() { … you code here … } }
orangy
filterInPlace
(private in stdlib), make it inline, and give it a good name.orangy