You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upickle and some other json libraries uses default arguments when field is not provided. It'll highly improve readability of yaml when you don't need to provide optional fields, and will give Devs much more flexibility.
//>usingscala"3.2.2"//>usingdep"org.virtuslab::scala-yaml:0.0.6"importorg.virtuslab.yaml.*caseclassFoo(id:String, name:String="optional") derivesYamlCodecvalexample1="id: 0112\n"+"name: Tottally not fake name\n"valexample2="id: 0113\n"
println(">"+ example1.as[Foo]) //> Right(Foo(0112,Tottally not fake name))
println(">"+ example2.as[Foo]) //> Left(ConstructError(Key name doesn't exist in parsed document)) // expected //> Right(Foo(0113,optional))
The text was updated successfully, but these errors were encountered:
scalway
changed the title
Use default arguments when field not provided
Use default arguments when field is not provided
Apr 8, 2023
I am looking for a similar feature, where defaults can be omitted from configuration files. However, I wonder if this should only be done if the type is Option. So instead of
Ha, after wondering why I see code related to the functionality I am looking for, I've discovered that this was only recently added: 9054aff and not yet released.
Upickle
and some otherjson
libraries uses default arguments when field is not provided. It'll highly improve readability ofyaml
when you don't need to provide optional fields, and will give Devs much more flexibility.The text was updated successfully, but these errors were encountered: