Skip to content

Commit

Permalink
Make method 'nestedApplications' public (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
keddelzz committed Apr 18, 2017
1 parent 472fb9f commit 2fbe29b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ case class LambdaApp(leftTerm: LambdaTerm, rightTerm: LambdaTerm) extends Lambda
override val freeVars: Set[String] = leftTerm.freeVars ++ rightTerm.freeVars

@tailrec
private[ast] final def nestedApplications(acc: List[LambdaTerm] = Nil): (LambdaTerm, List[LambdaTerm]) =
final def nestedApplications(acc: List[LambdaTerm] = Nil): (LambdaTerm, List[LambdaTerm]) =
leftTerm match {
case l: LambdaApp => l.nestedApplications(rightTerm :: acc)
case _ => (leftTerm, rightTerm :: acc)
Expand Down
22 changes: 22 additions & 0 deletions kernel/src/test/scala/me/rexim/morganey/ast/LambdaTermSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.rexim.morganey.ast

import me.rexim.morganey.ast.LambdaTermHelpers._
import me.rexim.morganey.helpers.TestTerms
import org.scalatest.{FlatSpec, Matchers}

class LambdaTermSpec extends FlatSpec with Matchers with TestTerms {

behavior of "A lambda application"

it should "be able to extract the nested applications" in {

def nestedApps(n: Int): LambdaApp =
(1 until n).map(_ => d).foldLeft(lapp(x, d))(lapp)

nestedApps(1).nestedApplications() should be (x, List(d))
nestedApps(2).nestedApplications() should be (x, List(d, d))
nestedApps(5).nestedApplications() should be (x, List(d, d, d, d, d))

}

}

0 comments on commit 2fbe29b

Please sign in to comment.