Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ object Decorators {
else x1 :: xs1
}

def foldRightBN[U](z: => U)(op: (T, => U) => U): U = xs match {
case Nil => z
case x :: xs1 => op(x, xs1.foldRightBN(z)(op))
def foldRightBN[U](z: => U)(op: (T, => U) => U): U =
xs.reverse.foldLeftBN(z)(op)

final def foldLeftBN[U](acc: => U)(op: (T, => U) => U): U = {
@tailrec def fold(xs: List[T], acc: => U): U = xs match {
case x :: xs1 => fold(xs1, op(x, acc))
case Nil => acc
}
fold(xs, acc)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

final def foldLeftBN[U](acc: => U)(op: (=> U, T) => U): U = {
  ...
  case x :: xs1 => fold(xs1, op(acc, x))

That's what I meant by "accumulator is the first arg of the closure"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is right, but if I do that the op must be put in another closure to reverse the parameter order.
I will make fold an inner method of foldRightBN and avoid this altogether.


final def hasSameLengthAs[U](ys: List[U]): Boolean = {
Expand Down