Scala function => as parameter -


could kindly explain me why following

  /**    * returns set transformed applying `f` each element of `s`.    */     def map(s: set, f: int => int): set = x => exists(s, y => f(y) == x) 

is not equivalent to

    def map(s: set, f: int => int): set = x => exists(s, f(x)) 

where "exists" function returns whether there exists bounded integer within s(the first argument) satisfies p(the second argument).

why need specify "y => f(y) == x"? million!

exists's second argument has type int => boolean (right?), in other words, expects function int boolean. now, f(x) doesn't conform type - has type int. - y => f(y) == x creates function correct type, returns true if input equals x.

if excess characters bug - can shorten bit using anonymous argument '_':

def map(s: set, f: int => int): set = x => exists(s, f(_) == x) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -