fixed minor issue in midterm

This commit is contained in:
Louis Heredero 2025-04-15 13:08:04 +02:00
parent 056305fd72
commit b53e0677cc
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 8 additions and 1 deletions

View File

@ -24,6 +24,13 @@ def predicates[T](list: List[T])(preds: List[T => Boolean]): List[T] = {
})
}
/*
// Better solution
def predicates[T](list: List[T])(preds: List[T => Boolean]): List[T] = {
preds.foldLeft(list)((acc, fun) => acc.filter(fun))
}
*/
def fixedPoint(f: Int => Int): Int => Int = {
@tailrec
def func(x: Int): Int = {

View File

@ -16,7 +16,7 @@ abstract class Text {
def tail: Text = {
this match {
case Chars(cs) => Chars(cs.tail)
case Concat(t1, t2) => if (t2.isEmpty) t1.tail else Concat(t1, t2.tail)
case Concat(t1, t2) => if (t1.isEmpty) t2.tail else Concat(t1.tail, t2)
}
}
def map(f: Char => Char): Text = {