user3139545
user3139545

Reputation: 7394

Sending functions to fold in Scala

How do I send an accumulation function to fold in Scala, the below example will say (Int,Int,Int) does not take parameters.

My questions are:

Upvotes: 0

Views: 68

Answers (4)

sebszyller
sebszyller

Reputation: 853

foldLeft is a curried function so it requires a . - go for xs.foldLeft and it will work.

Upvotes: 1

Chobeat
Chobeat

Reputation: 3525

The problem is here:

xs foldLeft((0,0,0))(logic _)

Never go for the dotless notation unless it's for an operator. This way it works.

xs.foldLeft((0,0,0))(logic _)

Without a context I believe this is idiomatic enough.

Upvotes: 2

talex
talex

Reputation: 20544

Try this

xs.foldLeft((0,0,0), logic)

Upvotes: 1

Nyavro
Nyavro

Reputation: 8866

I don't get the goal of your code but the problem you described can be solved this way:

val to = xs.foldLeft((0,0,0))(logic)

Upvotes: 1

Related Questions