Why isn't onEach function defined for Kotlin Arrays?
up vote
-2
down vote
favorite
The Collection API contains the onEach function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/on-each.html) which behaves like a non terminal sibling of forEach.
Why isn't onEach defined for Arrays?
collections kotlin api-design
add a comment |
up vote
-2
down vote
favorite
The Collection API contains the onEach function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/on-each.html) which behaves like a non terminal sibling of forEach.
Why isn't onEach defined for Arrays?
collections kotlin api-design
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
The Collection API contains the onEach function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/on-each.html) which behaves like a non terminal sibling of forEach.
Why isn't onEach defined for Arrays?
collections kotlin api-design
The Collection API contains the onEach function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/on-each.html) which behaves like a non terminal sibling of forEach.
Why isn't onEach defined for Arrays?
collections kotlin api-design
collections kotlin api-design
asked Nov 18 at 13:44
David Soroko
3,9021528
3,9021528
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The "Why" is probably not something to be answered here, it could be for many reasons including an oversight, something that just hasn't yet been done, some really good reason that it is a bad idea, or other. You can file a bug/request in https://youtrack.jetbrains.com/issues/KT (or see if there is an existing one).
In the meantime, you can easily have your own:
inline fun <T> Array<T>.onEach(action: (T) -> Unit): Array<T> {
return apply { for (element in this) action(element) }
}
inline fun IntArray.onEach(action: (Int) -> Unit): IntArray {
return apply { for (element in this) action(element) }
}
// and a version for each primitive array type would need to be created...
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we seeonEacheverywhere soon!
– Jayson Minard
Nov 18 at 18:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The "Why" is probably not something to be answered here, it could be for many reasons including an oversight, something that just hasn't yet been done, some really good reason that it is a bad idea, or other. You can file a bug/request in https://youtrack.jetbrains.com/issues/KT (or see if there is an existing one).
In the meantime, you can easily have your own:
inline fun <T> Array<T>.onEach(action: (T) -> Unit): Array<T> {
return apply { for (element in this) action(element) }
}
inline fun IntArray.onEach(action: (Int) -> Unit): IntArray {
return apply { for (element in this) action(element) }
}
// and a version for each primitive array type would need to be created...
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we seeonEacheverywhere soon!
– Jayson Minard
Nov 18 at 18:00
add a comment |
up vote
1
down vote
The "Why" is probably not something to be answered here, it could be for many reasons including an oversight, something that just hasn't yet been done, some really good reason that it is a bad idea, or other. You can file a bug/request in https://youtrack.jetbrains.com/issues/KT (or see if there is an existing one).
In the meantime, you can easily have your own:
inline fun <T> Array<T>.onEach(action: (T) -> Unit): Array<T> {
return apply { for (element in this) action(element) }
}
inline fun IntArray.onEach(action: (Int) -> Unit): IntArray {
return apply { for (element in this) action(element) }
}
// and a version for each primitive array type would need to be created...
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we seeonEacheverywhere soon!
– Jayson Minard
Nov 18 at 18:00
add a comment |
up vote
1
down vote
up vote
1
down vote
The "Why" is probably not something to be answered here, it could be for many reasons including an oversight, something that just hasn't yet been done, some really good reason that it is a bad idea, or other. You can file a bug/request in https://youtrack.jetbrains.com/issues/KT (or see if there is an existing one).
In the meantime, you can easily have your own:
inline fun <T> Array<T>.onEach(action: (T) -> Unit): Array<T> {
return apply { for (element in this) action(element) }
}
inline fun IntArray.onEach(action: (Int) -> Unit): IntArray {
return apply { for (element in this) action(element) }
}
// and a version for each primitive array type would need to be created...
The "Why" is probably not something to be answered here, it could be for many reasons including an oversight, something that just hasn't yet been done, some really good reason that it is a bad idea, or other. You can file a bug/request in https://youtrack.jetbrains.com/issues/KT (or see if there is an existing one).
In the meantime, you can easily have your own:
inline fun <T> Array<T>.onEach(action: (T) -> Unit): Array<T> {
return apply { for (element in this) action(element) }
}
inline fun IntArray.onEach(action: (Int) -> Unit): IntArray {
return apply { for (element in this) action(element) }
}
// and a version for each primitive array type would need to be created...
answered Nov 18 at 16:16
Jayson Minard
35.9k14104170
35.9k14104170
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we seeonEacheverywhere soon!
– Jayson Minard
Nov 18 at 18:00
add a comment |
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we seeonEacheverywhere soon!
– Jayson Minard
Nov 18 at 18:00
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
Thank you Jayson. I can see how the implementation of onEach in Collection translates to Array. My question is really about the API design. It came from me puzzling over the differences between the two APIs. Chunked and windowed are also missing from Array while fill is not in Collection
– David Soroko
Nov 18 at 16:30
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
David, "why" questions are not really great Stack Overflow questions if you want to talk to the language designers, go to the Kotlin forums, or the language design in the Kotlin slack. There are a lot of people working on Kotlin and you likely will get wrong answers here and assumptions (from people not even involved). But likely the answer is "we haven't gotten to it yet" given that Kotlin is always a work in progress...
– Jayson Minard
Nov 18 at 17:49
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Lastly, if you did go and ask for it on the Kotlin issue tracker, you would either see it happen, or receive a reason why it would not happen.
– Jayson Minard
Nov 18 at 17:52
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
Makes sense, will do.
– David Soroko
Nov 18 at 17:55
cool. let's all hope we see
onEach everywhere soon!– Jayson Minard
Nov 18 at 18:00
cool. let's all hope we see
onEach everywhere soon!– Jayson Minard
Nov 18 at 18:00
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361549%2fwhy-isnt-oneach-function-defined-for-kotlin-arrays%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown