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

Update versions #160

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ ThisBuild / githubWorkflowPublish := Seq(
// Project Definitions //
/////////////////////////

lazy val jsoniterVersion = "2.31.0"
lazy val jsoniterVersion = "2.32.0"
lazy val circeVersion = "0.14.10"
lazy val tapirVersion = "1.11.7"
lazy val zioVersion = "2.1.11"
lazy val tapirVersion = "1.11.10"
lazy val zioVersion = "2.1.13"
lazy val zioConfigVersion = "4.0.2"
lazy val zioSchemaVersion = "1.5.0"
lazy val zioJsonVersion = "0.7.3"
Expand Down
30 changes: 30 additions & 0 deletions modules/core/shared/src/main/scala/neotype/eval/Eval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ object Eval:
case '{ BigDecimal(${ Expr(double) }: Double) } => Some(Eval.Value(BigDecimal(double)))
case '{ (${ Expr(string) }: String).r } => Some(Eval.Value(string.r))

case '{ type a; type b; (${ Eval(a) }: `a`, ${ Eval(b) }: `b`): (`a`, `b`) } =>
Some(Eval.ProductValue("Tuple2", Map("_1" -> a, "_2" -> b)))
case '{ type a; type b; type c; (${ Eval(a) }: `a`, ${ Eval(b) }: `b`, ${ Eval(c) }: `c`): (`a`, `b`, `c`) } =>
Some(Eval.ProductValue("Tuple3", Map("_1" -> a, "_2" -> b, "_3" -> c)))

case Unseal(p @ Apply(Select(_, "apply"), Evals(args))) if p.tpe.typeSymbol.flags.is(Flags.Case) =>
val typeName = p.tpe.typeSymbol.name
val fieldNames = p.tpe.typeSymbol.primaryConstructor.paramSymss.flatten.map(_.name)
Expand Down Expand Up @@ -398,6 +403,9 @@ object Eval:
Some(Eval.Apply0(str, _.stripMargin, nullary("stripMargin")))
case '{ StringContext(${ Varargs(Exprs[String](strings)) }*).s(${ Varargs(Evals(evals)) }*) } =>
Some(Eval.EvalStringContext(strings.toList, evals.toList))
case '{ (${ Eval(str) }: String).zipWithIndex } =>
Some(Eval.Apply0(str, _.zipWithIndex, nullary("zipWithIndex")))

// string * int
case '{ (${ Eval(str) }: String) * (${ Eval(int) }: Int) } =>
Some(Eval.Apply1(str, int, _ * _, infix("*")))
Expand Down Expand Up @@ -493,6 +501,26 @@ object Eval:
case '{ type a; (${ Eval(set) }: Set[`a`]).apply(${ Eval(elem) }: `a`) } =>
Some(Eval.Apply1(set, elem, _.apply(_), (a, b) => s"$a($b)"))

// Tuple Operations
case '{ type a; type b; (${ Eval(tuple) }: (`a`, `b`))._1 } =>
Some(Eval.Apply0(tuple, _._1, nullary("_1")))
case '{ type a; type b; (${ Eval(tuple) }: (`a`, `b`))._2 } =>
Some(Eval.Apply0(tuple, _._2, nullary("_2")))
case '{ type a; type b; type c; (${ Eval(tuple) }: (`a`, `b`, `c`))._1 } =>
Some(Eval.Apply0(tuple, _._1, nullary("_1")))
case '{ type a; type b; type c; (${ Eval(tuple) }: (`a`, `b`, `c`))._2 } =>
Some(Eval.Apply0(tuple, _._2, nullary("_2")))
case '{ type a; type b; type c; (${ Eval(tuple) }: (`a`, `b`, `c`))._3 } =>
Some(Eval.Apply0(tuple, _._3, nullary("_3")))
case '{ type a; type b; type c; type d; (${ Eval(tuple) }: (`a`, `b`, `c`, `d`))._1 } =>
Some(Eval.Apply0(tuple, _._1, nullary("_1")))
case '{ type a; type b; type c; type d; (${ Eval(tuple) }: (`a`, `b`, `c`, `d`))._2 } =>
Some(Eval.Apply0(tuple, _._2, nullary("_2")))
case '{ type a; type b; type c; type d; (${ Eval(tuple) }: (`a`, `b`, `c`, `d`))._3 } =>
Some(Eval.Apply0(tuple, _._3, nullary("_3")))
case '{ type a; type b; type c; type d; (${ Eval(tuple) }: (`a`, `b`, `c`, `d`))._4 } =>
Some(Eval.Apply0(tuple, _._4, nullary("_4")))

// List Operations
case '{ type a; (${ Eval(list) }: List[`a`]).:+(${ Eval(elem) }: `a`) } =>
Some(Eval.Apply1(list, elem, _ :+ _, infix(":+")))
Expand Down Expand Up @@ -858,6 +886,8 @@ object Eval:
// iterable.zip(iterable)
// iterable.zipAll(iterable, 0, 0)
// iterable.zipWithIndex
case '{ type a; (${ Eval(list) }: Iterable[`a`]).zipWithIndex } =>
Some(Eval.Apply0(list, _.zipWithIndex, nullary("zipWithIndex")))

// Iterable Operations
// .mkString
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package neotype.eval

import neotype.TestMacros.*
import zio.test.*

object CollectionsSpec extends ZIOSpecDefault:
val spec =
suite("CollectionsSpec")(
evalTests.map { case (actual, expected) =>
test(s"eval($actual) == $expected") {
assertTrue(actual == expected)
}
}
)

inline def wrap[A](a: A): A = a

lazy val evalTests = List(
// List specific operations
eval(List(1, 2, 3)(2)) -> 3,
eval(List(1, 2, 3)) -> List(1, 2, 3),
eval(List(1, 2, 3) :+ 4) -> List(1, 2, 3, 4),
eval(5 :: List(1, 2, 3)) -> List(5, 1, 2, 3),
eval(List(1, 2, 3).head) -> 1,

// List transformations
eval(List(1, 2, 3).filter(_ > 1)) -> List(2, 3),
eval(List(1, 2, 3).map(_ * 2)) -> List(2, 4, 6),

// List state checks
eval(List(1, 2, 3).isEmpty) -> false,
eval(List(1, 2, 3).nonEmpty) -> true,

// Set operations
eval(Set(1, 2, 3)) -> Set(1, 2, 3),
eval(Set(1, 2, 3) + 4) -> Set(1, 2, 3, 4),
eval(Set(1, 2, 3).contains(2)) -> true,
eval(Set(1, 2, 3).contains(4)) -> false,

// Vector operations
eval(Vector(1, 2, 3)) -> Vector(1, 2, 3)
// eval(Vector(1, 2, 3) :+ 4) -> Vector(1, 2, 3, 4),
// eval(Vector(1, 2, 3).updated(1, 5)) -> Vector(1, 5, 3)
)
30 changes: 30 additions & 0 deletions modules/core/shared/src/test/scala/neotype/eval/EvalSetSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package neotype.eval

import neotype.TestMacros.*
import zio.test.*

object EvalSetSpec extends ZIOSpecDefault:
val spec =
suite("EvalSetSpec")(
evalTests.map { case (actual, expected) =>
test(s"eval($actual) == $expected") {
assertTrue(actual == expected)
}
}
)

private lazy val evalTests =
List(
// set expressions
eval(Set(1, 2, 3)) -> Set(1, 2, 3),
eval(Set(1, 2, 3) + 4) -> Set(1, 2, 3, 4),
eval(Set(1, 2, 3) - 2) -> Set(1, 3),
eval(Set(1, 2, 3).contains(2)) -> true,
eval(Set(1, 2, 3).contains(5)) -> false,
eval(Set(1, 2, 3)(5)) -> false,
eval(Set(1, 2, 3) intersect Set(2, 3, 4)) -> Set(2, 3),
eval(Set(1, 2, 3) ++ Set(2, 3, 4)) -> Set(1, 2, 3, 4),
eval(Set(1, 2, 3) -- Set(2, 3, 4)) -> Set(1),
eval(Set(1, 2, 3).filter(_ > 1)) -> Set(2, 3),
eval(Set(1, 2, 3).map(_ * 2)) -> Set(2, 4, 6)
)
Loading
Loading