Skip to content

TraversableOnce rewritten as IterableOnceIterableOnce #477

Open
@OndrejSpanel

Description

@OndrejSpanel

A simple source with TravesableOnce results in a strange IterableOnceIterableOnce identifier (the correct identifier is repeated twice):

package com.github.ondrejspanel.scafi

object TraversableOnce {

  def shuffle[T](random: scala.util.Random, src: TraversableOnce[T]): List[T] = {
    src.foldLeft(List.empty[T]) { (list, item) =>
      val len = list.length
      val index = (random.nextDouble() * (len + 1)).toInt
      list.patch(index, List(item), 0)
    }
  }

}

Using scalafix Collection213Upgrade was rewritten as:

package com.github.ondrejspanel.scafi

import scala.IterableOnce
object TraversableOnce {

  def shuffle[T](random: scala.util.Random, src: IterableOnceIterableOnce[T]): List[T] = {
    src.foldLeft(List.empty[T]) { (list, item) =>
      val len = list.length
      val index = (random.nextDouble() * (len + 1)).toInt
      list.patch(index, List(item), 0)
    }
  }

}

Complete project available at https://github.com/OndrejSpanel/ScalaFixSimple

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions