Venkat
05/07/2020, 11:06 PMfunc*()
call returns a valid string and it's gets appended to the mutable string variable returnString
. As far as I know, FP functions should not use any mutable values. So how would I replace those string appending lines?
private fun stringifyValue(): String {
var returnString = String()
returnString = returnString.plus("=")
returnString = returnString.plus(func1())
returnString = returnString.plus("+/")
returnString = returnString.plus(func2())
returnString = returnString.plus("@")
returnString = returnString.plus(func3())
returnString = returnString.plus("#")
returnString = returnString.plus(func4())
returnString = returnString.plus("%")
returnString = returnString.plus(func5())
returnString = returnString.plus("^")
return returnString
}
deactivateduser
05/07/2020, 11:16 PMstringifyValue
function and send it as the parameter to stringifyValue
.
Example:
fun stringifyValue ( vals: List<String> ): String {
//do what you need
}
fun main() {
val f1 = func1 ()
val f2 = func2 ()
val f3 = func3 ()
val f4 = func4 ()
val f5 = func5 ()
val str = stringifyValue ( listOf(f1, f2, f3, f4, f5) )
}
deactivateduser
05/07/2020, 11:18 PMZach Klippenstein (he/him) [MOD]
05/07/2020, 11:33 PMbuildString
if you need more flexibility. It would still be a pure function.Venkat
05/07/2020, 11:50 PMdeactivateduser
05/07/2020, 11:54 PM