Skip to content
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

TraversableOnce rewritten as IterableOnceIterableOnce #477

Open
OndrejSpanel opened this issue Aug 10, 2021 · 1 comment
Open

TraversableOnce rewritten as IterableOnceIterableOnce #477

OndrejSpanel opened this issue Aug 10, 2021 · 1 comment
Labels
area:scalafix rules bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@OndrejSpanel
Copy link
Member

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

@SethTisue SethTisue added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Aug 10, 2021
@SethTisue
Copy link
Member

Note that this is only a "good first issue" for those with an interest in working on the Scalafix rules, as opposed to the main part of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scalafix rules bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants