Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A LISP-style PersistentLinkedList would be nice #203

Open
sbohmann opened this issue Dec 8, 2024 · 1 comment
Open

A LISP-style PersistentLinkedList would be nice #203

sbohmann opened this issue Dec 8, 2024 · 1 comment

Comments

@sbohmann
Copy link

sbohmann commented Dec 8, 2024

It's the easiest-to-implement persistent data structure, and there are lots of classic functional algorithms that work best when building a list in reverse.

(cons 1 someList)

which creates a new list, starting with 1, followed by the contents of someList, might be e.g. expressed as

someList.prependedBy(1)

or, of course, some better, more concise name.

I'm not good at naming, so I tend to use very obvious, yet also very long, names 😅

@sbohmann
Copy link
Author

sbohmann commented Dec 8, 2024

https://github.com/sbohmann/aoc2024/blob/main/src/main/kotlin/persistentLinkedList/PersistentLinkedList.kt

An example implementation. It is really short due to the simple nature of the data structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant