CoopCoding
07/14/2019, 1:55 AMfun main() {
val strings = listOf("Hello", "World", "!")
val getLengthOfString = fun(str: String) : Int {
return str.length
}
val lengths = strings.map(getLengthOfString)
println(lengths)
}
But if the function is a regular function, I cant pass in the function name like so:
fun main() {
val strings = listOf("Hello", "World", "!")
fun getLengthOfString(str: String): Int {
return str.length
}
val lengths = strings.map(getLengthOfString)
println(lengths)
}leodeng
07/14/2019, 4:05 AM::getLengthOfStringCoopCoding
07/14/2019, 4:15 AMb00m
07/14/2019, 4:42 AMAl Warren
07/14/2019, 5:33 AMCoopCoding
07/14/2019, 5:48 AM:: basically used to satisfy the types?
Also, in most other languages, :: means bind, is that not the case here?
Thanks.Shawn
07/14/2019, 2:19 PM:: Foo::bar. Since the function exists within the local scope, there isn’t a name to really qualify its location by, so it comes out to just ::bar.Shawn
07/14/2019, 2:19 PM:: is used probably because reusing . is ambiguousCoopCoding
07/14/2019, 10:03 PMAl Warren
07/14/2019, 10:20 PMShawn
07/14/2019, 10:24 PM:: isn’t like bind or otherwise like plus or other infix operators - in this case it would fall in the same category as the dot operator or even -> in C