Skip to content

Commit

Permalink
fix: Wrong implementation for init/tail/(runtime) head
Browse files Browse the repository at this point in the history
  • Loading branch information
Iltotore committed Sep 20, 2024
1 parent a7e1d30 commit 91f4a64
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions main/src/io/github/iltotore/iron/constraint/collection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,13 @@ object collection:

expr.toExprList match
case Some(list) =>
list
.init
.map(applyConstraint(_, constraintExpr))
.foldLeft(Expr(true))((e, t) => '{ $e && $t })
list match
case Nil => Expr(true)
case _ =>
list
.init
.map(applyConstraint(_, constraintExpr))
.foldLeft(Expr(true))((e, t) => '{ $e && $t })

case None => '{ $expr.init.forall(c => ${ applyConstraint('c, constraintExpr) }) }

Expand Down Expand Up @@ -284,10 +287,13 @@ object collection:

expr.toExprList match
case Some(list) =>
list
.tail
.map(applyConstraint(_, constraintExpr))
.foldLeft(Expr(true))((e, t) => '{ $e && $t })
list match
case Nil => Expr(true)
case _ =>
list
.tail
.map(applyConstraint(_, constraintExpr))
.foldLeft(Expr(true))((e, t) => '{ $e && $t })

case None => '{ $expr.tail.forall(c => ${ applyConstraint('c, constraintExpr) }) }

Expand Down Expand Up @@ -381,7 +387,7 @@ object collection:
case Some(head) => applyConstraint(head, constraintExpr)
case None => Expr(false)

case None => '{ $expr.exists(c => ${ applyConstraint('c, constraintExpr) }) }
case None => '{ $expr.headOption.exists(c => ${ applyConstraint('c, constraintExpr) }) }

private def checkString[C, Impl <: Constraint[Char, C]](expr: Expr[String], constraintExpr: Expr[Impl])(using Quotes): Expr[Boolean] =
val rflUtil = reflectUtil
Expand Down

0 comments on commit 91f4a64

Please sign in to comment.