Skip to content

Commit

Permalink
Use enums
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-adam committed May 7, 2024
1 parent 36faf3a commit 82a91a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 82a91a6

Please sign in to comment.