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

runningFold method alongside tests #189

Closed
wants to merge 1 commit into from
Closed

runningFold method alongside tests #189

wants to merge 1 commit into from

Conversation

Wdestroier
Copy link

Hi,

I have added the runningFold method as requested in #151. Should the method stay in KtCollectionExtension?

The performed test is the same as the example present in Kotlin's documentation.

Reference: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/running-fold.html

@passsy
Copy link
Owner

passsy commented Oct 5, 2022

Kotlin impl

/// Returns a list containing the results of applying the given [operation]
/// function to each element in the original collection and the previous
/// accumulator value.
KtCollection<R> runningFold<R>(R initial, R Function(R, T) operation) {
Copy link
Owner

Choose a reason for hiding this comment

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

Change return type to KtList

/// Returns a list containing the results of applying the given [operation]
/// function to each element in the original collection and the previous
/// accumulator value.
KtCollection<R> runningFold<R>(R initial, R Function(R, T) operation) {
Copy link
Owner

Choose a reason for hiding this comment

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

Create extension for KtIterable, not KtCollection

@@ -205,6 +205,18 @@ void testCollection(KtCollection<T> Function<T>() emptyCollection,
});
});

group("runningFold", () {
Copy link
Owner

Choose a reason for hiding this comment

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

Don't forget the runningFoldIndexed variant 😉

@@ -205,6 +205,18 @@ void testCollection(KtCollection<T> Function<T>() emptyCollection,
});
});

group("runningFold", () {
test("running folds a string list", () {
final strings = listOf<String>("a", "b", "c", "d");
Copy link
Owner

Choose a reason for hiding this comment

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

Add a test where the list is empty

@Wdestroier Wdestroier closed this by deleting the head repository Oct 17, 2022
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

Successfully merging this pull request may close these issues.

2 participants