Use for questions about Scala's placeholder syntax for anonymous functions.
Questions tagged [scala-placeholder-syntax]
23 questions
1
vote
1 answer
I found inconsistency in Scala's underscore
This works: (1 to 5).reduceLeft( _+_ )
but this doesn't: (x:Int,y:Int)=>_+_
:8: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$plus(x$2))
(x:Int,y:Int)=>_+_
^
:8:…

WeiChing 林煒清
- 4,452
- 3
- 30
- 65
0
votes
1 answer
Argument placeholder syntax in Haskell, like _ in Scala?
In Scala I could do this:
lines.filter(_.length < 10) // notice the _ acting as the argument
In Haskell the best I can come up with is:
filter ((< 10) . length) lines // point-free with `.` :(
So basically in Haskell there is no way to do…

Ashkan Kh. Nazary
- 21,844
- 13
- 44
- 68
0
votes
1 answer
How to add text outlines to text within Powerpoint via Apache POI:
Does anyone have an idea how we can add outlines to text (text outline) within powerpoint templates (ppxt) using Apache POI? What I have gathered so far is that the XSLFTextRun class does not have a method to get/ set the text outline for a given…

kajoe14
- 23
- 5
0
votes
1 answer
Why sortWith(lt: (A, A) => Boolean) require a function with two params but can use compareTo which have only one param?
As https://www.scala-lang.org/api/current/scala/collection/immutable/List.html#sortWith(lt:(A,A)=%3EBoolean) :
List("Steve", "Tom", "John", "Bob").sortWith(_.compareTo(_) < 0) = List("Bob", "John", "Steve", "Tom")
the param of sortWith is:
lt: (A,…

wang kai
- 1,673
- 3
- 12
- 21
0
votes
1 answer
What does _ mean in this method which already takes a default value?
I am working on a test suite which has a helper method such as:
def setupMocks(isChild: Boolean = false): Unit
and in some of the tests, it is invoked as :
setupMocks(_)
whereas in other tests, it is invoked as :
setupMocks()
What does the _ do…

Saturnian
- 1,686
- 6
- 39
- 65
0
votes
1 answer
How to pass Function result to math.max
I am able to do this:
def largestAt(fun: (Int) => Int, inputs: Seq[Int]):Int = {
inputs.reduceLeft(math.max(_,_))
}
But, when I am trying to do this:
def largestAt(fun: (Int) => Int, inputs: Seq[Int]):Int = {
…

Abhay Kumar
- 522
- 3
- 9
0
votes
3 answers
Force grouping of ascription on underscore in scala
I am trying to do:
MyObject.myMethod(_:MyType.myAttribute)
This fails with
type myAttribute is not a member of object MyObject
which is correct. The problem is that I want to call myMethod on myAttribute of _:MyType, not ascribe MyType:myAttribute…

taz
- 1,506
- 3
- 15
- 26
0
votes
4 answers
Underscore Causing Difficulties
I have the following code, which is supposed to search through an array and see if the anything matches the second argument.
def any(check: Set[Any], expr: Boolean): Boolean = {
var checked = check.filter(_ => expr)
if (checked == Set())
…

Bobby Tables
- 1,154
- 4
- 15
- 25