I have the following java code:
`final Optional<Date> storyDate = extractDate.andThen(toDate).apply(storyFrom);`
I have already asked about this code. The solution there may affect this (I’m not sure). extractDate has been converted to
`private val extractDate = { from:Optional<String> ->
from.flatMap({ line -> Regex.extractMatch("((\\d{2}-){2}(\\d{4}))", line) }) }`
The converter generates for the given java code generates:
val storyDate = extractDate.andThen(toDate).apply(storyFrom)
storyFrom has been converted to:
val storyFrom: Optional<String> = lines.stream().filter(Predicate<String> { this.storyFrom(it) }).findFirst()
Now, I am aware that andThen is not available in kotlin (I think it should be as it’s used often enough in java code).
I’ve added the following to address the missing andThen (and this seems to have worked)
infix fun <F: (T1)->T2,T1,T2,T3> F.andThen(g: (T2)->T3): (T1)->T3 = { g(this(it)) }
So in my kotlin code:
`final Optional<Date> storyDate = extractDate.andThen(toDate).apply(storyFrom);`
I get the compile errors…
At the .apply I get
Error:(46, 47) Kotlin: Type inference failed: inline fun T.apply(block: T.() → Unit): T
cannot be applied to
receiver: (Optional) → Optional arguments: (Optional<String!>!)
and at the storyFrom I get error:
Error:(46, 53) Kotlin: Type mismatch: inferred type is Optional<String!>! but ((Optional) → Optional).() → Unit was expected
as far as I can tell the issue is related to how the apply and the andThen work together…