Code Monkey home page Code Monkey logo

cedi-config's People

Contributors

anakos avatar matthughes avatar mpilquist avatar sbuzzard avatar scala-steward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cedi-config's Issues

Provide a `ConfigParser.failed` constructor

So, I'm trying to manually parse sealed trait families. I'd like to avoid the automatic derivation.

Here's how it looks like now:

sealed trait Timeframe                                       
object Timeframe {                                           
  case class Absolute(from: Long, to: Long) extends Timeframe
  case class Relative(since: String) extends Timeframe       
}                                                            

val timeframeParser: ConfigParser[Timeframe] =                                                                
  string("type").bind {                                                                                       
    case "absolute" => (long("from") :: long("to")).as[Timeframe.Absolute]                                    
    case "relative" => string("since").map(Timeframe.Relative)                                                
    case otherwise =>                                                                                         
      anonymous(_ => Left(ConfigErrors.of(ConfigError.BadValue(ConfigKey.Relative("type"), otherwise, None))))
  }                                                                                                           

I'm pretty happy with it, apart from the error case for the discriminator. It'd be really helpful if the library provided a ConfigParser.failure method (A cats.MonadError instance would be even better :-)).

Derivation of nested case classes

Hi-

At present, this library does not seem to support full derivation of nested case classes: i.e. - given the following set of case classes

final case class Both(left: Wibble, right: That)
final case class Wibble(value: Int)
final case class Wobble(value: List[String])

then simply calling derived[Both] without explicitly defining implicit values for both derived[Wibble] and derived[Wobble], will yield compilation errors indicating that a ConfigParser needs to be in scope for each component type x of Both.

Would you welcome a PR supporting the ability to fully auto-derive nested case classes?

Thanks
Alex

Is there a better way to derive ConfigParser without leaking DerivedConfigFieldParser?

I have an ADT as given below:


abstract sealed class Location(val name: String)

object Location {
  final case object AustraliaEast extends Location("australiaeast")

  def fromString(name: String): Location = name match {
    case AustraliaEast.name => AustraliaEast
  }
}

I derive the ConfigParser for Location by specifying the DerivedConfigFieldParser for location.

 implicit val locDerivedConfigFieldParser: DerivedConfigFieldParser[Location] =
      implicitly[DerivedConfigFieldParser[String]].map(Location.fromString)

Is there already a better way of doing it?

If not, it would be more intuitive to define just a ConfigParser[Location] (using the ConfigParser[String]). Something along the below lines.

implicit val configParser: ConfigParser[Location] = 
  ConfigParser[String].map(Location.fromString)

Looking at the code, it feels we could bring this behavior.

Add support for NonEmptyList and NonEmptyVector

Enhance API be adding support for NonEmptyList and NonEmptyVector:

An example of code would be:

def nonEmptyList[A](key: String)(cpl: String => ConfigParser[List[A]]): ConfigParser[NonEmptyList[A]] = cpl(key) bind { case head :: tail => ConfigParser.pure(NonEmptyList(head, tail)) case Nil => ConfigParser(s"non-empty-list failure for $key") { _ => Left(ConfigErrors.of(ConfigError.WrongType(ConfigKey.Relative(key), "expected non-empty list", None))) } }

and

def nonEmptyVector[A](key: String)(cpv: String => ConfigParser[Vector[A]]): ConfigParser[NonEmptyVector[A]] = cpv(key) bind { case Vector() => ConfigParser(s"non-empty-vector failure for $key") { _ => Left(ConfigErrors.of(ConfigError.WrongType(ConfigKey.Relative(key), "expected non-empty vector", None))) } case v => ConfigParser.pure(NonEmptyVector(v.head, v.tail)) }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.