Skip to content

feat: Implement RepeatNode - #14

Merged
l2hyunwoo merged 8 commits into
mainfrom
feature/#10
Jan 2, 2026
Merged

feat: Implement RepeatNode#14
l2hyunwoo merged 8 commits into
mainfrom
feature/#10

Conversation

@l2hyunwoo

Copy link
Copy Markdown
Contributor

Issue

close #10

Description

Implement RepeatNode. This node repeats its children N times sequentially.

Additional Context

What if count is zero or below zero?

  • count = 0 → Returns empty list (valid: "repeat zero times")
  • count < 0 → Throws IllegalArgumentException (fail-fast for logical errors)

This follows Compose's implicit contract where invalid indices cause exceptions (e.g., LazyColumn.items(count)).

inline fun <T> LazyListScope.items(
    items: List<T>,
    noinline key: ((item: T) -> Any)? = null,
    noinline contentType: (item: T) -> Any? = { null },
    crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit,
) =
    items(
        count = items.size,
        key = if (key != null) { index: Int -> key(items[index]) } else null,
        contentType = { index: Int -> contentType(items[index]) },
    ) {
        itemContent(items[it])
    }

@l2hyunwoo l2hyunwoo self-assigned this Jan 2, 2026
@l2hyunwoo l2hyunwoo added the enhancement New feature or request label Jan 2, 2026
@l2hyunwoo
l2hyunwoo requested a review from wisemuji January 2, 2026 12:42

@wisemuji wisemuji left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some suggestions & questions!

val childEvents = child.collectEvents(state.currentTimeMs)
val nextTime = childEvents
.maxOfOrNull { it.startTimeMs + it.durationMs }
?: state.currentTimeMs

@wisemuji wisemuji Jan 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic closely mirrors SequenceNode.collectEvents. If SequenceNode logic is reused or if RepeatNode simply treated its children as an implicit SequenceNode, the code could be DRY-er.
-> This means that test cases will be more concise as well!
-> There's no need to implement this suggestion in the current pull request; it’s just something to keep in mind 🙂

Comment thread jindong/src/commonTest/kotlin/io/github/jindong/node/RepeatNodeTest.kt Outdated
Comment thread jindong/src/commonTest/kotlin/io/github/jindong/node/RepeatNodeTest.kt Outdated
Comment thread jindong/src/commonTest/kotlin/io/github/jindong/node/RepeatNodeTest.kt Outdated
Comment thread jindong/src/commonMain/kotlin/io/github/jindong/node/RepeatNode.kt
Comment thread jindong/src/commonMain/kotlin/io/github/jindong/node/RepeatNode.kt Outdated
Comment thread jindong/src/commonTest/kotlin/io/github/jindong/node/RepeatNodeTest.kt Outdated
@l2hyunwoo
l2hyunwoo requested a review from wisemuji January 2, 2026 13:36

@wisemuji wisemuji left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏

@l2hyunwoo
l2hyunwoo merged commit fd5f1ae into main Jan 2, 2026
2 checks passed
@l2hyunwoo
l2hyunwoo deleted the feature/#10 branch January 2, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement RepeatNode

2 participants