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

Handle indexed sequence, and allow more backends for ConfigProvider #7823

Merged
merged 10 commits into from Feb 16, 2023

Conversation

afsalthaj
Copy link
Contributor

@afsalthaj afsalthaj commented Feb 13, 2023

Handling indexed sequence as given in the below example code, will allow more backends for ConfigProvider in zio-config.

The implementation is a simplified version of #7798, and it keeps backward compatibility.

object Hello extends App {

  val map =
    Map(
      "employees[0].age" -> "1",
      "employees[0].id" -> "1",
      "employees[1].age" -> "2",
      "employees[1].id" -> "2",
      "employees[2].id" -> "3",

    )

  val provider =
    ConfigProvider.fromMap(map)

  case class Employee(age: Option[Int], id: Int)

    val employee: Config[Employee] =
      Config.int("age").optional.zip(Config.int("id")).map(Employee.tupled)

  case class AppConfig(list1: List[Employee], dummyIds: List[Int])

  val config: Config[AppConfig] =
    Config.listOf("employees", employee).zip(Config.listOf("dummyIds.[0]", Config.int)).map(AppConfig.tupled)

  val pgm =
    provider.load(config)

  val result =
    Unsafe.unsafe(implicit u => zio.Runtime.default.unsafe.run(pgm.either).getOrThrowFiberFailure())

  assert(result == Right(AppConfig(List(Employee(Some(1),1), Employee(Some(2),2), Employee(None,3)),List(4, 6, 6))))

}

@afsalthaj afsalthaj changed the title Handle sequence for indices Handle indexed sequence, and allow more backends for ConfigProvider Feb 13, 2023
@afsalthaj afsalthaj marked this pull request as ready for review February 15, 2023 05:33
adamgfraser
adamgfraser previously approved these changes Feb 15, 2023
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go when tests are passing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants