2 ms·
> Are there other languages that do this so nicely? It's the perfect blend of OO and functional. Python compressor = lambda x: x / 2 compressor(5) help
by paulddraper 3y ago
> Are there other languages that do this so nicely? It's the perfect blend of OO and functional.
Python
compressor = lambda x: x / 2
compressor(5)
helpful_compressor = lambda x: x / 2
helpful_compressor.help = "compressor"
helpful_compressor(5)
helpful_compressor.help
Scala
val compressor = (x: double) => x / 2
compressor(5)
object helpfulCompressor {
def apply(x: double) = x / 2
val help = "compressor"
}
helpfulCompressor(5)
helpfulCompressor.help
Ruby also has .call...but I can't remember it well enough