question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default value for optional field

See original GitHub issue

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:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
loonydevcommented, Sep 16, 2020

We can move option to the end and it’s reduce amount of code:

final case class Label(
    name: String,
    color: String,
    id: Option[Long] = None,
    description: Option[String] = None,
    url: Option[String] = None,
    default: Option[Boolean] = None
)

So you can use it

Label("name","color")
0reactions
fedefernandezcommented, Sep 18, 2020

@loonydev I see, thanks for the explanation. Let’s go for the defaults then.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found