-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
/// 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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", () { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
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