Skip to content

Commit

Permalink
feat: Add sealed classes example to client code
Browse files Browse the repository at this point in the history
The code changes in this commit add a new file `Sealed.scala` to the `examples/client/src/main/scala/samples` directory. This file contains an example of using sealed classes in Scala. It defines a sealed trait `Animal` and two case classes `Horse` and `Lama` that extend the `Animal` trait. It also includes a case class `Owner` that has a `name` and a `pet` field of type `Animal`. The commit also updates the `HelloWorld.scala` file to include the new `sealedClasses` sample component.

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
cheleb and renovate[bot] committed Aug 28, 2024
1 parent eef47d6 commit 5e8e7ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/client/src/main/scala/HelloWorld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object App extends App {

private val demos = Seq(
samples.simple,
samples.sealedClasses,
samples.either,
samples.enums,
samples.person,
Expand Down
29 changes: 29 additions & 0 deletions examples/client/src/main/scala/samples/Sealed.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package samples

import dev.cheleb.scalamigen.{*, given}

import com.raquo.laminar.api.L.*

import com.raquo.airstream.state.Var

sealed trait Animal
case class Horse(name: String, age: Int) extends Animal
case class Lama(name: String, age: Int, splitDistance: Int) extends Animal

case class Owner(name: String, pet: Animal)

val sealedClasses = Sample(
"Sealed", {

val eitherVar = Var(Owner("Agnes", Horse("Scala le chat", 6)))

div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
eitherVar.asForm
)
}
)
3 changes: 2 additions & 1 deletion examples/client/src/main/scala/samples/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ object Tree:
case (Empty, Node(_, _, _)) => false
case (Node(_, left1, right1), Node(_, left2, right2)) =>
isSameStructure(left1, left2) && isSameStructure(right1, right2)
implicit def treeInstance[A](using

given treeInstance[A](using
default: Defaultable[A]
)(using Form[A]): Form[Tree[A]] =
new Form[Tree[A]] { self =>
Expand Down

0 comments on commit 5e8e7ae

Please sign in to comment.