From 82a91a6a72c7f45fd9f6b0421d6740c8edbd4a62 Mon Sep 17 00:00:00 2001 From: Kamil Adam Date: Tue, 7 May 2024 19:54:09 +0200 Subject: [PATCH] Use enums --- .../catculator/core/adt/tree/BinaryTree.scala | 12 +++++------- .../pl/writeonly/catculator/core/adt/tree/Tree.scala | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/BinaryTree.scala b/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/BinaryTree.scala index a1e2530..aa8533e 100644 --- a/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/BinaryTree.scala +++ b/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/BinaryTree.scala @@ -1,11 +1,9 @@ package pl.writeonly.catculator.core.adt.tree -object BinaryTree { - - case class Leaf[A](leaf: A) extends BinaryTree[A] +enum BinaryTree[+A]: + case Leaf(leaf: A) + case Node(first: BinaryTree[A], follow: BinaryTree[A]) - case class Node[A](first: BinaryTree[A], follow: BinaryTree[A]) - extends BinaryTree[A] +object BinaryTree { } - -sealed trait BinaryTree[+A] +q \ No newline at end of file diff --git a/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/Tree.scala b/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/Tree.scala index 2432209..418c5a3 100644 --- a/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/Tree.scala +++ b/catculator-core/src/main/scala/pl/writeonly/catculator/core/adt/tree/Tree.scala @@ -2,13 +2,11 @@ package pl.writeonly.catculator.core.adt.tree import cats.data.NonEmptyList +enum Tree[A]: + case Leaf(leaf: A) + case Node(children: NonEmptyList[Tree[A]]) + object Tree { def node[A](head: Tree[A], tail: Tree[A]*): Tree[A] = Node(NonEmptyList(head, tail.toList)) - - case class Leaf[A](leaf: A) extends Tree[A] - - case class Node[A](children: NonEmptyList[Tree[A]]) extends Tree[A] } - -sealed trait Tree[+A]