Reading the syntax off of this listing at scala-lang -



Reading the syntax off of this listing at scala-lang -

just learning basic stuff here.

it appears count method vector useful me exercise i'm working on, reading entry @ scala-lang i'm having hard time understanding how utilize it, syntactically speaking.

here's entry says:

count(p: (a) => boolean): int

i think that's supposed telling me syntax utilize when calling method.

it tells me "p" predicate satisfied. okay, know predicate in abstact. predicate in scala though?

then there's colon. type that? or meta-linguistic notation of kind?

then there's rocket. okay. word boolean--but doing there? assume don't literally type "boolean." (do i?)

anyway, see problem(s).

how work?

you there!

count needs parameter p of type (:) a (rocket) boolean, 'a' type of elements stored vector. have provide function a boolean.

so can utilize this:

val v = vector(1, 2, 3, 4, 5, 6) // == vector[int](1, 2, 3, 4, 5, 6) def odd(elem: int): boolean = { elem % 2 == 0 } v.count(odd) // == 3

or using syntactic sugar:

val v = vector(1, 2, 3, 4, 5, 6) // == vector[int](1, 2, 3, 4, 5, 6) v.count(_ % 2 == 0) // == 3

scala

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -