![]() In the given solution for the problem, the anonymous function can be written more explicitly likeĭef lastNth ( n : Int, l : List ): A = The Scala tour has a good explanation of anonymous functions, which are pretty simple. There is another thing to note in the folding solution, however, which is the way Scala defines anonymous functions. I consider that two answers to be exhaustive so I will not add any explanation about this topic. ![]() I recommend two readings from Stackoverflow: this answer about the meaning of partial function, partially applied function and currying, and this answer (which also links the first one) that explores the difference between partially applied and currying. ![]() This has to do with the concepts of partially applied functions (NOT partial functions) and currying. The first strange thing that I see here is that the function is defined with two sets of brackets, the first encompassing "the start value" z and the second what seems the definition of a function. The first element receives the initial value. ![]() So basically the foldLeft() method visits each element of the list from left to right and applies a function passing the result of the previous application. Def foldLeft ( z : B )( f : ( B, A ) ⇒ B ): BĪnd the documentation states: "Applies a binary operator to a start value and all elements of this sequence, going left to right". ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |