@rkenmi - A quick look at Scala and the syntax

A quick look at Scala and the syntax


Negation, ∀, ∃

A quick look at Scala and the syntax


Back to Top

Updated on February 6, 2017

The syntax in Scala can look confusing very fast..

def exists(s: Set, p: Int => Boolean): Boolean = !forall(s, (x: Int) => !p(x))

p here is a function parameter; okay, I get that.

p: Int => Boolean means that this function takes an Int parameter and returns a Boolean at the end.

The exists function itself returns a Boolean.

Now, what does exists do?

It runs a function called forall, which takes two parameters, a Set, and a function that takes an Int parameter and returns a Boolean. Actually, the parameter requirements for forall is equivalent to exists.

Now look at this part.

!forall(s, (x: Int) => !p(x))

The ! isn't difficult to figure out; the simple meaning is that it negates things.

I have toyed with Scala for two weeks and I find how practical Scala can be, but the syntax takes some getting used to.


Article Tags:
Scalaintro