Own-Programming-Language-Tu.../examples/functions/tomap.own

8 lines
344 B
Scala
Raw Normal View History

2024-04-28 22:39:30 +03:00
use std, functional
data = ["apple", "banana", "cherry", "apricot", "coconut"]
println tomap(data, def(str) = str.substring(0, 1))
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase)
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase, ::joinValues)
def joinValues(oldValue, newValue) = oldValue + ", " + newValue