scala - Apply a sequence of functions to value and get the final result -
i wish apply sequence of functions object (each of functions may return same or modified object) , ultimate result returned last function.
is there idiomatic scala way turn (pseudocode):
val pipeline = listmap(("a" -> obj1), ("b" -> obj2), ("c" -> obj3)) into this?
val initial_value = something("foo", "bar") val result = obj3.func(obj2.func(obj1.func(initial_value))) the pipeline initialized @ runtime , contains undetermined number of "manglers".
i tried foreach requires intermediate var store result, , foldleft works on types of listmap, while initial value , result of type something.
thanks
this should it:
pipeline.foldleft(initial_value){case (acc, (k,obj)) => obj.func(acc)} no idea why pipeline contains pairs, though.
Comments
Post a Comment