Skip to content

Commit 0439f60

Browse files
authored
Use liftN from cats 2.13 (#514)
* Use liftN from cats 2.13 * reformat
1 parent f1065cf commit 0439f60

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

modules/core/src/main/scala/playground/QueryCompiler.scala

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package playground
22

33
import cats.Apply
44
import cats.data.IorNec
5+
import cats.data.Kleisli
56
import cats.data.NonEmptyChain
67
import cats.syntax.all.*
78
import playground.CompilationErrorDetails.*
@@ -31,20 +32,13 @@ object QueryCompiler {
3132
fa: QueryCompiler[A]
3233
)(
3334
f: A => B
34-
): QueryCompiler[B] = fa.compile(_).map(f)
35+
): QueryCompiler[B] = Kleisli(fa.compile).map(f).run(_)
3536

3637
def ap[A, B](
3738
ff: QueryCompiler[A => B]
3839
)(
3940
fa: QueryCompiler[A]
40-
): QueryCompiler[B] =
41-
wast =>
42-
(ff.compile(wast), fa.compile(wast)).parMapN(
43-
(
44-
a,
45-
b,
46-
) => a(b)
47-
)
41+
): QueryCompiler[B] = Kleisli(ff.compile).parAp(Kleisli(fa.compile)).run(_)
4842

4943
}
5044

modules/parser/src/main/scala/playground/smithyql/parser/Parsers.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,10 @@ object Parsers {
201201
lazy val struct: Parser[Struct[T]] = {
202202
type TField = Binding[T]
203203

204-
val field: Parser[TField] =
205-
(
206-
ident.map(_.map(Identifier.apply)) <* tokens.colon.orElse(tokens.equalsSign),
207-
tokens.withComments(node),
208-
).mapN(Binding.apply[T])
204+
val field: Parser[TField] = Binding[T].liftN(
205+
ident.map(_.map(Identifier.apply)) <* tokens.colon.orElse(tokens.equalsSign),
206+
tokens.withComments(node),
207+
)
209208

210209
// field, then optional whitespace, then optional coma, then optionally more `fields`
211210
val fields: Parser0[Struct.Fields[T]] = field
@@ -252,11 +251,12 @@ object Parsers {
252251
.withContext("query_operation_name")
253252
}
254253

255-
val query: Parser[Query[T]] =
256-
(
254+
val query: Parser[Query[T]] = Query[T]
255+
.liftN(
257256
tokens.withComments(queryOperationName, left = false),
258257
tokens.withComments(struct, right = false),
259-
).mapN(Query.apply).withContext("query")
258+
)
259+
.withContext("query")
260260

261261
val runQuery
262262
: Parser[RunQuery[T]] = tokens.withComments(query).map(RunQuery(_)).withContext("run_query")
@@ -269,8 +269,10 @@ object Parsers {
269269
.map(Prelude.apply)
270270
.withContext("prelude")
271271

272-
val sourceFile: Parser0[SourceFile[T]] = (prelude, tokens.withComments0(statement.rep0))
273-
.mapN(SourceFile.apply[T])
272+
val sourceFile: Parser0[SourceFile[T]] = SourceFile[T].liftN(
273+
prelude,
274+
tokens.withComments0(statement.rep0),
275+
)
274276

275277
implicit class ParserOps[A](
276278
parser: Parser[A]

0 commit comments

Comments
 (0)