-
Notifications
You must be signed in to change notification settings - Fork 75
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
Default value for optional field #549
Comments
Sounds good to me, I know those optional parameters do not need to be at the end, but if they aren’t, then you will be required to use named arguments syntax for any following arguments, as you suggested: Label(name = "String", color = "") Another alternative to re-order the case class is providing a companion object: final case class Label(
id: Option[Long],
name: String,
description: Option[String],
url: Option[String],
color: String,
default: Option[Boolean]
)
object Label {
def apply(name: String, color: String): Label = this(None, name, None, None, color, None)
} |
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") |
Great, will do soon! |
@loonydev my vote is for the @juanpedromoreno's proposal. I'm not a great fan of the default values in the arguments and it's usually considered a bad practice. |
Hi @fedefernandez, Well I'm agreed with you about default values, but it's
And if with label it's not too complex, so what about It's create huge amount of work to understand and fix all cases in |
@loonydev I see, thanks for the explanation. Let's go for the defaults then. |
Hi guys, during working on #547 I saw that optional fields don't have default parameter.
For example, for
issue.createLabel
user need to have instance ofdomain.Label
with(name:String, color:String)
but he must to create object likeLabel(None,name, None, None, color, None)
Current model
proposal
So user can create label like
Label(name = "String",color = "")
.WDYT?
The text was updated successfully, but these errors were encountered: