This week's giveaway is in the Groovy forum. We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line! See this thread for details.

Newbie questions are the best kind! Many of us are still exploring Scala and every newbie question helps us to find new frontiers we'd never even heard of before. Finding new frontiers is half the fun!

I wasn't really familiar with the term arity before but this was fun to explore.

According to wikipedia:

From a mathematical point of view, a function of n arguments can always be considered as a function of one single argument... The same is true for programming languages, where functions taking several arguments could always be defined as functions taking a single argument of some complex type such as a tuple, or in languages with higher-order functions, by currying.

My understanding is that arity is used to define the most primitive mathematical concepts. If we had a function that computed 6 values as a-b*c/x-y*z, we'd actual have a bunch of binary arities and not a 6-arity function. 7 = nullary, no operators -7 = unary, one operator that needs one parameter 7+7 = binary, one operator that needs two parameters true?0:7 = ternary, one operator (though the syntax is two separate symbols) that needs three operators assuming you don't use the "Elvis" version

I'm not sure a varargs is necessary. My hunch is that the Scala strategy would be to put all your values in a List or tuple, which can then be passed as a single argument.

Scala does have a variable argument syntax. You have to use the * notation.

The type of the varargs reference is a Seq. In the given example args is a Seq[A]. This syntax is used in a number of places in the standard Scala libs, one of the most used is in the List object where the apply() method is defined to take a variable number of arguments.

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter

@Marc, Thanks for the link to that blogpost. Good read.

My followup questions

Are FunctionN traits similar to Procs in Ruby ? Procs are those objects created by passing a block to a lambda method.

I'm trying to digest Partial functions right now. Doets and Van Eijck's book The Haskell Road to Logic, Math and programming has a section dedicated to it. I'll post again if I'm stumped.

Hi Pho, I have heard the term Functor used like that before. Also, I have seen a discussion on the Scala mailing list about it. FYI, I call it a misuse and so do many others, but let's not get hung up on that.

Instead, here is a more concise definition. A functor is any implementation of the following interface:

...such that 2 laws satisfy:

identity. forall x. fmap(identity, x) == x

composition. forall f g x. fmap(f, fmap(g, x)) == fmap(f compose g, x)

Notice the kind of the type constructor argument F (* -> *). There are several type constructors that satisfy this kind. Just to name a few:

scala.List

scala.Option

scala.Stream

scala.Either.LeftProjection

scala.Either.RightProjection

scala.Function1#Apply[T] (i.e. curry the first type argument)

You might be keen to implement this interface with these type constructors just to observe each functor manifest