does kotlin provide any list implementation that c...
# announcements
does kotlin provide any list implementation that can do efficient (constant-time) cons/cdr, for use when designing tail recursive functions that operate on lists?
you can write an extension for linkedlist.
if you mean java's LinkedList i believe that's doubly linked, so efficient (immutable) cons/cdr isn't possible
there is kotlinx.collections.immutable project that may be of help to you, but I'm not sure if that's exactly what you're looking for.
Do you mean a stack? You want to push and pop data no? Technically you can just use a list and add an element or remove one at the end, or use deque if you want a nicer interface and want to push and pop on both sides
in the end i just went with a simple custom definition of a linked list:
class Node<T>(val head: T, val tail: Node<T>?)
. i guess i was just a bit too used to languages like scala/haskell where this is the default list type and constant-time cons is a very fundamental operator it also looks like the
type (immutable, stateless) might be relevant for functional idioms