-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
provide ability to write a NULL #28
Comments
what about providing alternative to Option (with easy conversion) sealed trait Nullable[+A] {
def toOption: Option[A]
}
final case class NotNull[+A](x: A) extends Nullable[A] {
def toOption: Option[A] = Some(x)
}
case object IsNull extends Nullable[Nothing] {
def toOption: Option[Nothing] = None
}
object Nullable {
implicit class NullableOption[+A](val opt: Option[A]) extends AnyVal {
def toNullable: Nullable[A] = opt.fold[Nullable[A]](IsNull)(NotNull.apply)
}
} |
usage could be case class SomeTable(couldBeNull: Nullable[String])
val str: Option[String] = Some("a string")
SomeTable(str.toNullable) or case class SomeTable(couldBeNull: Nullable[String])
object SomeTable {
def apply(couldBeNull: Option[String]) = new SomeTable(couldBeNull.toNullable)
}
SomeTable(Some("a string")) // just works in the latter case, maybe it makes more sense to have a implicit def option2nullable[A](opt: Option[A]): Nullable[A]) = opt.toNullable
case class SomeTable(couldBeNull: Nullable[String])
SomeTable(Some("a string")) // just works |
this is implemented. no docs yet, so leaving this here until then |
i feel like this going to loose type constraints on fields of data record |
there were some cases in my project where "absence of data" and "data set to null" were semantically different, so I wanted to enable this. if you don't care about that difference, then just don't use |
also, thanks for reminding me about this. it shouldn't take much to add this documentation, so i should just do it |
None will always remove the write. provide a way to write down a NULL
The text was updated successfully, but these errors were encountered: