-
Notifications
You must be signed in to change notification settings - Fork 112
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 zio.Config.Switch for discriminated sum types #1167
Changes from all commits
a3181de
547259b
280a545
3fa819d
b7d8f5a
870623b
39790df
9dcd2a6
5b1a2e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ trait ConfigSyntax { | |
case config: FallbackWith[B] => FallbackWith(loop(config.first), loop(config.second), config.f) | ||
case config: Fallback[B] => Fallback(loop(config.first), loop(config.second)) | ||
case Sequence(config) => Sequence(loop(config)) | ||
case Switch(config, map) => Switch(config, map.map { case (k, v) => k -> loop(v) }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we will keep it for now. |
||
case Nested(name, config) => Nested(f(name), loop(config)) | ||
case MapOrFail(original, mapOrFail) => MapOrFail(loop(original), mapOrFail) | ||
case Table(valueConfig) => Table(loop(valueConfig)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ final case class describe(describe: String) extends StaticAnnotation | |
final case class name(name: String) extends StaticAnnotation | ||
|
||
/** | ||
* nameWithLabel can be used for class names, such that the name of the class should be part of the product with keyName | ||
* discriminator can be used for class names, such that the name of the class should be part of the product with keyName | ||
* as `keyName`. | ||
* | ||
* Example: | ||
* {{{ | ||
* @nameWithLabel("type") | ||
* @discriminator("type") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
* sealed trait FooBar | ||
* case class Bar(x: Int) extends FooBar | ||
* case class Foo(y: String) extends FooBar | ||
|
@@ -48,12 +48,12 @@ final case class name(name: String) extends StaticAnnotation | |
* | ||
* }}} | ||
* | ||
* If annotation is `name` instead of `nameWithLabel`, then name of the case class becomes a parent node | ||
* If annotation is `name` instead of `discriminator`, then name of the case class becomes a parent node | ||
* | ||
* {{{ | ||
* Foo : { | ||
* x : Int | ||
* } | ||
* }}} | ||
*/ | ||
final case class nameWithLabel(keyName: String = "type") extends StaticAnnotation | ||
final case class discriminator(keyName: String = "type") extends StaticAnnotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases
k
will beString
, but I wonder if there could be a better support for polymorphic key type ofConfig.Switch[A, B]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going to be hard at DynamicMap level in zio core, as this key gets propagated all over.