Usage
Basic usage
import dev.cheleb.scalamigen.*
This import is necessary to bring the implicit conversions into scope.
Now you can use the asForm method on any Var to render a form for the value it holds with double binding.
case class Cat(name: String, age: Int)
val eitherVar = Var(Cat("Scala le chat", 6))
eitherVar.asForm // (2) form rendering
As long as the case class is built on elments that have a Form[..] instance, the form will be rendered correctly.
Supported types
String,Int,Long,Double,BooleanLocalDateOption[A]List[A]Either[A, B]IronType[T, C]Positive
Customizing the form rendering
At anytime you can customize the form rendering by providing a Form instance for the type you want to render.
opaque type
opaque type Password = String
object Password:
def apply(password: String): Password = password
given Form[Password] = secretForm(apply) // (1) form instance
IronType
Iron type are supported as long as their base type is supported by the library. For example, Positive is a wrapper around Int and Long and can be used as such.
In this article