Skip to content

Commit

Permalink
Update example In A Nutshell
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Sep 22, 2023
1 parent 1b7e011 commit e846d7e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
19 changes: 15 additions & 4 deletions examples/src/main/scala/soda/example/inanutshell/InANutshell.soda
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ class MaxAndMin

end

class Pair [A : Type] [B : Type]

abstract
fst : A
snd : B

end

class MinMaxPair
extends
Pair [Int] [Int]

abstract
min : Int
max : Int

fst : Int = min

snd : Int = max

end

class Indexable
Expand All @@ -62,10 +76,7 @@ class Example
index : Int

min_max (a : Int) (b : Int) : MinMaxPair =
MinMaxPair_ (
min := MaxAndMin_ () .min (a) (b),
max := MaxAndMin_ () .max (a) (b)
)
MinMaxPair_ (min := MaxAndMin_ () .min (a) (b) ) (max := MaxAndMin_ () .max (a) (b) )

end

Expand Down
21 changes: 17 additions & 4 deletions examples/src/main/scala/soda/example/inanutshell/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ trait MaxAndMin

case class MaxAndMin_ () extends MaxAndMin

trait Pair [A , B ]
{

def fst : A
def snd : B

}

case class Pair_ [A, B] (fst : A, snd : B) extends Pair [A, B]

trait MinMaxPair
extends
Pair [Int, Int]
{

def min : Int
def max : Int

lazy val fst : Int = min

lazy val snd : Int = max

}

case class MinMaxPair_ (min : Int, max : Int) extends MinMaxPair
Expand All @@ -79,10 +95,7 @@ trait Example
def index : Int

def min_max (a : Int) (b : Int) : MinMaxPair =
MinMaxPair_ (
min = MaxAndMin_ () .min (a) (b),
max = MaxAndMin_ () .max (a) (b)
)
MinMaxPair_ (min = MaxAndMin_ () .min (a) (b) , max = MaxAndMin_ () .max (a) (b) )

}

Expand Down

0 comments on commit e846d7e

Please sign in to comment.