Default value for optional field
See original GitHub issueIssue Description
Hi guys, during working on https://github.com/47degrees/github4s/pull/547 I saw that optional fields don’t have default parameter.
For example, for issue.createLabel
user need to have instance of domain.Label
with (name:String, color:String)
but he must to create object like Label(None,name, None, None, color, None)
Current model
final case class Label(
id: Option[Long],
name: String,
description: Option[String],
url: Option[String],
color: String,
default: Option[Boolean]
)
proposal
final case class Label(
id: Option[Long] = None,
name: String,
description: Option[String] = None,
url: Option[String] = None,
color: String,
default: Option[Boolean] = None
)
So user can create label like Label(name = "String",color = "")
.
WDYT?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Typescript: Apply default values to optional fields nested in an ...
If the options object is not passed in, I need all fields of the objects value to be defaults. From there, I need...
Read more >KIP-581: Value of optional null field which has default value
Generally, when an optional field which has default value is null , we can treat it as null or default value , it...
Read more >Language Guide | Protocol Buffers - Google Developers
Defining A Message Type; Scalar Value Types; Optional Fields And Default Values; Enumerations; Using Other Message Types; Nested Types; Updating A Message ...
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Kotlin Data Class With Optional Fields - Baeldung
Learn how to create a class instance with optional fields. ... For all constructor parameters, we set a default value:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We can move option to the end and it’s reduce amount of code:
So you can use it
@loonydev I see, thanks for the explanation. Let’s go for the defaults then.