FlatMap Explained - Kotlin Collections

Поделиться
HTML-код
  • Опубликовано: 14 ноя 2024

Комментарии • 7

  • @rabiunislam9302
    @rabiunislam9302 2 года назад

    Very good explanation..keep it up

  • @pradeepkumarreddykondreddy7048
    @pradeepkumarreddykondreddy7048 4 года назад +1

    .map{} returns List right ? How does it becomes List

    • @CodyEngelCodes
      @CodyEngelCodes  4 года назад

      In this example it would return a List of a List of authors because we are mapping the Authors from each Book. Using flat map will flatten that into a single list.

  • @ChrisAthanas
    @ChrisAthanas 3 года назад +1

    Best explanation, thank you

  • @harikrishnanmurugan5385
    @harikrishnanmurugan5385 3 года назад

    Is there another function "flatMapTo", what is the purpose of it?

    • @CodyEngelCodes
      @CodyEngelCodes  3 года назад

      The "flatMapTo" function works well if you created a list ahead of time and want to flat map some items to that list. I've been working with Kotlin since late 2016 and honestly can't think of a time I needed to use the "flatMapTo" function, but I'm sure there are some niche scenarios where it'd make sense to use it.