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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 13:44









      David Soroko

      3,9021528




      3,9021528
























          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...





          share|improve this answer





















          • 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 see onEach everywhere soon!
            – Jayson Minard
            Nov 18 at 18:00











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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...





          share|improve this answer





















          • 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 see onEach everywhere soon!
            – Jayson Minard
            Nov 18 at 18:00















          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...





          share|improve this answer





















          • 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 see onEach everywhere soon!
            – Jayson Minard
            Nov 18 at 18:00













          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...





          share|improve this answer












          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...






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 see onEach everywhere 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










          • 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 see onEach everywhere 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Paul Cézanne

          UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

          Angular material date-picker (MatDatepicker) auto completes the date on focus out