I'm having trouble using minByOrNull within buildM...
# getting-started
d
I'm having trouble using minByOrNull within buildMap, getting odd type mismatch errors about TypeVariables. Am I missing something? https://pl.kotl.in/GnuWqAS_Z
(I'm trying to make a Map out of another Map by first filtering it based on one condition, and then removing the smallest element based on a second condition. I figure buildMap is a nice way to not have to have an explicit MutableMap in the middle. But minByOrNull doesn't work on the
this
of the buildMap closure for some reason...)
OK I guess it's a type inference thing; specifying
<String, F>
myself on
buildMap
(or its return value) works
a
You could also simplify
output
into something like this for more readability / avoiding type inference oddities:
d
@asdf asdf thanks, but in the real version I'm doing a
remove
on the output of the minByOrNull 🙂
s
your code also works if you add type annotations to buildMap
Copy code
val output = buildMap<String, F> {
looks like you reached the limits of type inference
i
d
thanks!