Skip to content

Commit

Permalink
use new Scala 3 syntax. prepare latest Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Aug 26, 2024
1 parent b8e0eb4 commit f215483
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private[focus] trait KeywordParserBase extends ParserBase {
Some(
Name(keyword),
FromType(code.tpe.widen),
TypeArgs(inferredTypeArgs.map(_.tpe): _*),
TypeArgs(inferredTypeArgs.map(_.tpe)*),
ValueArgs(),
RemainingCode(code)
)
Expand All @@ -32,8 +32,8 @@ private[focus] trait KeywordParserBase extends ParserBase {
Some(
Name(keyword),
FromType(code.tpe.widen),
TypeArgs(inferredTypeArgs.map(_.tpe): _*),
ValueArgs(valueArgs: _*),
TypeArgs(inferredTypeArgs.map(_.tpe)*),
ValueArgs(valueArgs*),
RemainingCode(code)
)

Expand All @@ -42,7 +42,7 @@ private[focus] trait KeywordParserBase extends ParserBase {
Some(
Name(keyword),
FromType(code.tpe.widen),
TypeArgs(directTypeArgs.map(_.tpe): _*),
TypeArgs(directTypeArgs.map(_.tpe)*),
ValueArgs(),
RemainingCode(code)
)
Expand All @@ -53,7 +53,7 @@ private[focus] trait KeywordParserBase extends ParserBase {
Some(
Name(keyword),
FromType(code.tpe.widen),
TypeArgs(allTypeArgs.map(_.tpe): _*),
TypeArgs(allTypeArgs.map(_.tpe)*),
ValueArgs(),
RemainingCode(code)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait AsParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordAs extends FocusParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait AtParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordAt extends FocusParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait EachParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordEach extends FocusParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait IndexParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordIndex extends FocusParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.SelectParserBase

private[focus] trait SelectFieldParser {
this: FocusBase with SelectParserBase =>
this: FocusBase & SelectParserBase =>

import this.macroContext.reflect._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.SelectParserBase

private[focus] trait SelectOnlyFieldParser {
this: FocusBase with SelectParserBase =>
this: FocusBase & SelectParserBase =>

import this.macroContext.reflect._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait SomeParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordSome extends FocusParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase
import monocle.internal.focus.features.KeywordParserBase

private[focus] trait WithDefaultParser {
this: FocusBase with KeywordParserBase =>
this: FocusBase & KeywordParserBase =>

object KeywordWithDefault extends FocusParser {

Expand Down
12 changes: 6 additions & 6 deletions core/shared/src/main/scala/monocle/Fold.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ trait Fold[S, A] extends Serializable { self =>

/** find the first target matching the predicate */
def find(p: A => Boolean): S => Option[A] =
foldMap(a => Some(a).filter(p))(_)(Monoids.firstOption)
foldMap(a => Some(a).filter(p))(_)(using Monoids.firstOption)

/** get the first target */
def headOption(s: S): Option[A] =
foldMap(Option(_))(s)(Monoids.firstOption)
foldMap(Option(_))(s)(using Monoids.firstOption)

/** get the last target */
def lastOption(s: S): Option[A] =
foldMap(Option(_))(s)(Monoids.lastOption)
foldMap(Option(_))(s)(using Monoids.lastOption)

/** check if at least one target satisfies the predicate */
def exist(p: A => Boolean): S => Boolean =
foldMap(p(_))(_)(Monoids.any)
foldMap(p(_))(_)(using Monoids.any)

/** check if all targets satisfy the predicate */
def all(p: A => Boolean): S => Boolean =
foldMap(p(_))(_)(Monoids.all)
foldMap(p(_))(_)(using Monoids.all)

/** calculate the number of targets */
def length(s: S): Int =
foldMap(_ => 1)(s)

/** check if there is no target */
def isEmpty(s: S): Boolean =
foldMap(_ => false)(s)(Monoids.all)
foldMap(_ => false)(s)(using Monoids.all)

/** check if there is at least one target */
def nonEmpty(s: S): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/monocle/Traversal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait PTraversal[S, T, A, B] extends PSetter[S, T, A, B] with Fold[S, A] { self
*/
def parModifyF[F[_]](f: A => F[B])(s: S)(implicit F: Parallel[F]): F[T] =
F.sequential(
modifyA(a => F.parallel(f(a)))(s)(F.applicative)
modifyA(a => F.parallel(f(a)))(s)(using F.applicative)
)

override def some[A1, B1](implicit ev1: A =:= Option[A1], ev2: B =:= Option[B1]): PTraversal[S, T, A1, B1] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object FilterIndex extends FilterIndexFunctions {
.traverse { case (k, v) =>
(if (predicate(k)) f(v) else v.pure[F]).tupleLeft(k)
}
.map(kvs => SortedMap(kvs: _*)(ok.toOrdering))
.map(kvs => SortedMap(kvs *)(ok.toOrdering))
}
}

Expand Down

0 comments on commit f215483

Please sign in to comment.