scala - Apply several transformation functions to string -
suppose have 2 methods:
def a(s: string) = s + "..." def b(s: string) = s + ",,," and want create 3rd method call both methods:
def c (s: string) = a(b(s)) how can in idiomatic scala way?
i think it's better aggregate functions list , sequentially apply them:
list(a_, b_)
i think it's better aggregate functions list , sequentially apply them.
you specifying expected type:
scala> val fs: list[string => string] = list(a,b) fs: list[string => string] = list(<function1>, <function1>) scala> fs.foldleft("something")((s,f) => f(s)) res0: string = something...,,,
Comments
Post a Comment