Skip to content

Better ImmutableList #3816

Draft
wadoon wants to merge 5 commits into
mainfrom
weigl/ilist
Draft

Better ImmutableList #3816
wadoon wants to merge 5 commits into
mainfrom
weigl/ilist

Conversation

@wadoon
Copy link
Copy Markdown
Member

@wadoon wadoon commented May 16, 2026

Issue

We currently have two implementations of immutable sequences with ImmutableList and ImmutableArray. This requires conversions sometimes, but mainly it leads to confusion about which implementation should be taken.

Intended Change

This PR unifies everything under ImmutableList.

There are two fresh children classes: ImmutableListArray and ImmutableListList. Both behave like ImmutableList, but use different data storage (T[] or List<T>) in the background.

Some operations from ImmutableList are quite expensive on this data storages, e.g., tail() or reverse(). Therefore, I introduced views that emulate these operations, without copying the data, i.e.,

  • ImmutableListConcat as ImmutableList#prepend(other)
  • ImmutableListReverse for ImmutableList#reverse()
  • ImmutableListSubList for ImmutableList#take(n), ImmutableList#skip(n), ImmutableList#tail()

These operations are now in $O(1)$.

The class ImmutableArray should be considered obsolete.

Developers should use only the methods and functions of ImmutableList. Implementation may override them if there is a faster implementation, e.g, tail() on ImmutableSList.

Plan

  • Renaming ImmutableSList to ImmutableList.
  • More, even more test cases, coverage is not so bad, but could be better.
  • Update the JavaDoc documentation

Type of pull request

  • Refactoring (behaviour should not change or only minimally change)

  • New feature (non-breaking change which adds functionality)

  • There are changes to the (Java) code

Ensuring quality

  • I made sure that introduced/changed code is well documented (javadoc and inline comments).

@wadoon wadoon requested a review from unp1 May 16, 2026 14:55
@wadoon wadoon self-assigned this May 16, 2026
@wadoon wadoon added the Java Pull requests that update Java code label May 16, 2026
@wadoon wadoon added this to the v3.1.0 milestone May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant