Last active
February 3, 2026 20:24
-
-
Save dacr/92179e9589f18a08784a729137fc85ec to your computer and use it in GitHub Desktop.
ZIO learning - application configuration / published by https://github.com/dacr/code-examples-manager #df673a20-1dd6-41f1-af38-7390da22d64d/1a3ab6ac1d0eb0a8f3d704f5acfff60e236613a6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : ZIO learning - application configuration | |
| // keywords : scala, zio, learning, pure-functional, typesafeconfig, config,, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : df673a20-1dd6-41f1-af38-7390da22d64d | |
| // created-on : 2021-03-29T19:16:09Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio:2.0.13" | |
| //> using dep "dev.zio::zio-config:4.0.0-RC14" | |
| //> using dep "dev.zio::zio-config-typesafe:4.0.0-RC14" | |
| //> using dep "dev.zio::zio-config-magnolia:4.0.0-RC14" | |
| //> using dep "dev.zio::zio-config-refined:4.0.0-RC14" // type-level predicates which constrain the set of values described for data types. | |
| // --------------------- | |
| import zio.* | |
| import zio.config.* | |
| import zio.config.typesafe.* | |
| import zio.config.magnolia.* | |
| case class Truc(name: String) | |
| case class MyConfig(truc: Truc) | |
| object Encapsulated extends ZIOAppDefault { | |
| // ------------------------------------------------------------- | |
| val hoconConfigSource = | |
| ConfigProvider.fromHoconString( | |
| input = s"""truc { | |
| | name=blah | |
| |} | |
| |""".stripMargin | |
| ) | |
| // ------------------------------------------------------------- | |
| val logic = for { | |
| config <- hoconConfigSource.load(deriveConfig[MyConfig]) | |
| _ <- Console.printLine(config.truc.name) | |
| } yield () | |
| // ------------------------------------------------------------- | |
| override def run = { | |
| logic | |
| } | |
| } | |
| Encapsulated.main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment