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

Use [T: Xxx], not explicit implicit ev: Xxx[T] #259

Merged
merged 1 commit into from
Nov 29, 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
29 changes: 15 additions & 14 deletions metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ sealed abstract class Conf extends Product with Serializable {
final def diff(other: Conf): Option[(Conf, Conf)] = ConfOps.diff(this, other)
override final def toString: String = show
def as[T](implicit ev: ConfDecoder[T]): Configured[T] = ev.read(this)
def getSettingOrElse[T](setting: Setting, default: T)(implicit
ev: ConfDecoder[T],
def getSettingOrElse[T: ConfDecoder](
setting: Setting,
default: T,
): Configured[T] = ConfGet
.getOrElse(this, default, setting.name, setting.alternativeNames: _*)
def get[T](path: String, extraNames: String*)(implicit
ev: ConfDecoder[T],
): Configured[T] = ConfGet.get(this, path, extraNames: _*)
def getOrElse[T](path: String, extraNames: String*)(default: T)(implicit
ev: ConfDecoder[T],
def get[T: ConfDecoder](path: String, extraNames: String*): Configured[T] =
ConfGet.get(this, path, extraNames: _*)
def getOrElse[T: ConfDecoder](path: String, extraNames: String*)(
default: T,
): Configured[T] = ConfGet.getOrElse(this, default, path, extraNames: _*)

def getNested[T](keys: String*)(implicit ev: ConfDecoder[T]): Configured[T] =
ConfGet.getNested(this, keys: _*)
def getNested[T: ConfDecoder](keys: String*): Configured[T] = ConfGet
.getNested(this, keys: _*)
}

object Conf {
Expand All @@ -50,9 +50,8 @@ object Conf {
Try(fromBigDecimal(BigDecimal(str.toDouble))).getOrElse(fromString(str))
def fromString(str: String): Conf = Conf.Str(str)

def parseCliArgs[T](args: List[String])(implicit
settings: Settings[T],
): Configured[Conf] = CliParser.parseArgs[T](args)
def parseCliArgs[T: Settings](args: List[String]): Configured[Conf] =
CliParser.parseArgs[T](args)
def parseFile(file: File)(implicit
parser: MetaconfigParser,
): Configured[Conf] = Input.File(file).parse
Expand Down Expand Up @@ -116,8 +115,10 @@ object Conf {
): Configured[A] = ConfGet.getKey(conf, path)
.fold(Configured.ok(state))(ev.read(Some(state), _))

def getSettingEx[A](state: A, conf: Conf, setting: Setting)(implicit
ev: ConfDecoderEx[A],
def getSettingEx[A: ConfDecoderEx](
state: A,
conf: Conf,
setting: Setting,
): Configured[A] = getEx(state, conf, setting.name +: setting.alternativeNames)

implicit class ConfImplicit(conf: Conf) {
Expand Down
23 changes: 8 additions & 15 deletions metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ object ConfDecoder {
): ConfDecoder[T] = fromPartial(ev.runtimeClass.getName)(f)

@deprecated("Use from instead", "0.9.12")
def instanceF[T](f: Conf => Configured[T])(implicit
ev: ClassTag[T],
): ConfDecoder[T] = from(f)
def instanceF[T: ClassTag](f: Conf => Configured[T]): ConfDecoder[T] = from(f)

def from[T](f: Conf => Configured[T]): ConfDecoder[T] = f(_)

@deprecated("Use fromPartial instead", "0.9.12")
def instanceExpect[T](expect: String)(f: PartialFunction[Conf, Configured[T]])(
implicit ev: ClassTag[T],
def instanceExpect[T: ClassTag](expect: String)(
f: PartialFunction[Conf, Configured[T]],
): ConfDecoder[T] = fromPartial(expect)(f)

def fromPartial[A](expect: String)(
Expand Down Expand Up @@ -108,19 +106,14 @@ object ConfDecoder {

// XXX: remove this method when MIMA no longer an issue
@deprecated("Use canBuildFromAnyMapWithStringKey instead", "0.9.2")
def canBuildFromMapWithStringKey[A](implicit
ev: ConfDecoder[A],
classTag: ClassTag[A],
): ConfDecoder[Map[String, A]] = CanBuildFromDecoder.map[A, Map]
def canBuildFromMapWithStringKey[A: ConfDecoder: ClassTag]
: ConfDecoder[Map[String, A]] = CanBuildFromDecoder.map[A, Map]

implicit def canBuildFromAnyMapWithStringKey[A, CC[_, _]](implicit
ev: ConfDecoder[A],
factory: Factory[(String, A), CC[String, A]],
classTag: ClassTag[A],
implicit def canBuildFromAnyMapWithStringKey[A: ClassTag: ConfDecoder, CC[_, _]](
implicit factory: Factory[(String, A), CC[String, A]],
): ConfDecoder[CC[String, A]] = CanBuildFromDecoder.map[A, CC]

implicit def canBuildFromConfDecoder[C[_], A](implicit
ev: ConfDecoder[A],
implicit def canBuildFromConfDecoder[C[_], A: ConfDecoder](implicit
factory: Factory[A, C[A]],
classTag: ClassTag[A],
): ConfDecoder[C[A]] = CanBuildFromDecoder.list[C, A]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metaconfig
import scala.language.dynamics

class ConfDynamic(val asConf: Configured[Conf]) extends Dynamic {
def as[T](implicit ev: ConfDecoder[T]): Configured[T] = asConf.andThen(_.as[T])
def as[T: ConfDecoder]: Configured[T] = asConf.andThen(_.as[T])
def selectDynamic(name: String): ConfDynamic = {
val result = asConf.andThen(_.getConf(name))
ConfDynamic(result)
Expand Down
Loading