LoginSignup
1
0

More than 5 years have passed since last update.

ScalaでTree構造を表現するためのクラス

Posted at

同一型のみによるTree構造は結構簡単。
Dot(節点)とLine(辺)の2種類のクラスからなるTreeはちょっと工夫する必要がある。

case class Dot[D, L](value: D, lines: Line[L, D]*)
case class Line[L, D](value: L, dot: Dot[D, L])

型クラスを使うとこういう構造が表しやすい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0