https://kotlinlang.org logo
Title
e

Ellen Spertus

09/30/2019, 9:06 PM
I’m thinking functional style and, rather than overwriting the current state of my object, a colleague suggested I append the latest state to a list, so I never overwrite/throw away information.
t’s not necessary for correctness. He just thought it would be more elegant. I think I’ll just change the state for now. I can always create my own AppendOnlyList if I want to. I just wanted to make sure I wasn’t overlooking a common data structure. (I’m new to Kotlin but not to programming. I’m thinking from a Scheme perspective without set!)
s

Shawn

09/30/2019, 9:10 PM
you can definitely just
+
lists returned by
listOf()
and reassign to a var or return the new list within, say, a
fold
call
the latter would be more scheme-like I’d think, but I’m no expert there
e

Ellen Spertus

09/30/2019, 9:11 PM
I think I’ll stick with
var
. After all, it is in the language and is more efficient.
Scheme-like would be to have only immutable lists and create a new list every time you want to add an element. Not the most efficient. 🐌
s

Shawn

09/30/2019, 9:12 PM
for sure, you know your problem space better than we do
b

Bob Glamm

09/30/2019, 9:18 PM
Creation of new lists is not necessarily any more inefficient than mutating an existing list
e

Ellen Spertus

09/30/2019, 9:19 PM
Good point, because you can just point to the old list and not worry about its being changed. @Bob Glamm