Home > other >  Ask a Scala syntax problem!!!!!!!!!!!!
Ask a Scala syntax problem!!!!!!!!!!!!

Time:09-28

When watching a program written in Scalding, see so a function definition:
Def flatMap/A, T (fs: (Fields, Fields)) (fn: A=& gt; TraversableOnce [T]) (implicit conv: TupleConverter [A], setter: TupleSetter [T]) : Pipe={
Conv. AssertArityMatches (fs) _1)
Setter. AssertArityMatches (fs) _2)
Each (fs) (new FlatMapFunction/A, T (fn, _, conv, setter))
}

Call it:
FlatMap (' line - & gt; 'word) {lineA: String=& gt; Tokenize (lineA)}//tokenize (is a function, need not consider)


I don't understand:
Function definitions clearly is 3 layers of brackets, also like a 3 layer curry is changed, but the calling function, why use a () and a {} is done??
And lineA: String=& gt; Tokenize (lineA) what is the meaning of this sentence? ! If it is passed in an anonymous function as an argument, also should be add parentheses: (lineA: String)=& gt; Tokenize (lineA)

CodePudding user response:

Nobody answer? Here should be scala player!

CodePudding user response:

Nobody know??
I add cent!!!!!!!!!!!!!!!

CodePudding user response:

Nobody answer? Here should be master of scala

CodePudding user response:

I don't understand the pupil

CodePudding user response:

The first parameter is the pair
The second parameter is a function that calls {} is used instead of the specific function
The third parameter is implicit, context has implicit reference can omit this parameter

CodePudding user response:

Don't to imperative programming language (c/c + +) to understand it, learn it, will be in accordance with its way of thinking, functional
LineA: String=& gt; Tokenize (lineA) means of type String variable lineA, his incoming function tokenize
Why the somebody else is this kind of writing, the language must be written imperative languages (lineA: String)=& gt; Tokenize (lineA)

CodePudding user response:

'the line - & gt; 'word passed the fs: (Fields, Fields)
LineA: String=& gt; Pass the tokenize (lineA) (fn: A=& gt; TraversableOnce [T])
Implicit conv: TupleConverter [A], setter: TupleSetter [T] there's no need to, as long as there is implicit context definition line
In scala, if only one parameter, the function call can use {} instead of ()
Here in currie, (fn: A=& gt; TraversableOnce [T]) small brackets only one parameter, so when the call can use {} instead of ()
Such as the following example
 object Test {
Def f (a: Int)={a}
Def main (args: Array [String]) {
Val a={f 15}//here use {} instead of ()
Println (a)
}
}
  • Related