Any concise way to define a constant function (mapping) in scala -


i newbie in scala. have following code define constant function returns true 1,2,3 , false other integers.( function defines a set {1,2,3} of integers):

val a= node1 _ def node1(x:int):boolean={             if (x==1 || x ==2 || x==3){true}             else{false} } 

is there way define function more concisely?

val a: int => boolean = set(1, 2, 3).contains(_) 

which same as

val a: int => boolean = set(1, 2, 3) 

this because set's apply method same contains method.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -