I'm trying to map over an array using a multiline anonymous closure and I'm having trouble. E.g.
val httpHosts = stringHosts.map(host => {
val hostAndPort = host.split(":")
return new HttpHost(hostAndPort(0), hostAndPort(1).toInt, "http")
})
I'm receiving the following warning:
enclosing method executePlan has result type Unit: return value of type org.apache.http.HttpHost discarded
Which implies that httpHosts
is an Array[Unit]
and not an Array[HttpHost]
.
I understand that I can split this into two maps, but for the sake of understanding Scala better, what am I doing wrong here when doing this in a multiline closure?
question from:https://stackoverflow.com/questions/65930388/scala-multiline-anonymous-closure-mapping-over-array