Day 1: 'Infix modifier is required on "filter" in "kotlin.collections"'

I am just getting started with Kotlin and following the walkthroughs. One of them is this example:

fun main(args : Array<String>) {
    args filter {true} forEach {print ("Hello, $it!")}
}

very pretty, but IntelliJ gives me red squigglies on the filter and forEach symbols and complains that infix modifiers are required on “kotlin.collections.” I googled around and tried a bunch of hacks, but don’t see a way to fix this.

EDIT:

Interspersing dots, fixes it, of course

args.filter {true}.forEach {print ("Hello, $it!")

but I still wonder whether and how the infix syntax from the walkthroughs is available

May be those walkthroughs are outdated? Those methods don’t have infix modifier, you can’t call them in infix position.

1 Like

thanks. looks like this is the case. I’m ok with dots.

I’m still having this issue.

This is a three-year-old topic where OP didn’t use proper syntax to call methods by leaving out the required dots, “.”, in his code.

It seems like the original poster was incorrectly copying a walkthrough, or perhaps the walkthrough was incorrect.

@Tyluur, what is your issue? Which lines of code throw your error? What solutions have you already tried? When you say “this issue” do you mean you get a similar error message to OP? Can you narrow it down or at least describe what you mean by “this issue”?

1 Like