-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from KacperFKorban/sum-types
Sum types
- Loading branch information
Showing
7 changed files
with
202 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package guinep.compiletest | ||
|
||
def personsAge(name: String): Int = name match { | ||
case "Bartek" => 20 | ||
case _ => 0 | ||
} | ||
|
||
def upperCaseText(text: String): String = | ||
text.toUpperCase | ||
|
||
def add(a: Int, b: Int) = | ||
a + b | ||
|
||
def concat(a: String, b: String) = | ||
a + b | ||
|
||
def giveALongText(b: Boolean): String = | ||
if b then "XXXXXXXXXXXXXXXXXXXXXX" else "-" | ||
|
||
case class Add(a: Int, b: Int) | ||
|
||
def addObj(add: Add) = | ||
add.a + add.b | ||
|
||
def greetMaybeName(maybeName: Option[String]): String = | ||
maybeName.fold("Hello!")(name => s"Hello, $name!") | ||
|
||
enum Language: | ||
case English, Polish | ||
|
||
def greetInLanguage(name: String, language: Language): String = | ||
language match | ||
case Language.English => s"Hello, $name!" | ||
case Language.Polish => s"Cześć, $name!" | ||
|
||
sealed trait MaybeString | ||
case class JustString(value: String) extends MaybeString | ||
case object NoString extends MaybeString | ||
|
||
def nameWithPossiblePrefix(name: String, maybePrefix: MaybeString): String = | ||
maybePrefix match | ||
case JustString(value) => s"$value $name" | ||
case NoString => name | ||
|
||
enum MaybeString1: | ||
case JustString(value: String) | ||
case NoString | ||
|
||
def nameWithPossiblePrefix1(name: String, maybePrefix: MaybeString1): String = | ||
maybePrefix match | ||
case MaybeString1.JustString(value) => s"$value $name" | ||
case MaybeString1.NoString => name | ||
|
||
@main | ||
def run: Unit = | ||
guinep.web( | ||
personsAge, | ||
upperCaseText, | ||
add, | ||
concat, | ||
giveALongText, | ||
addObj, | ||
// greetMaybeName, | ||
greetInLanguage, | ||
nameWithPossiblePrefix, | ||
nameWithPossiblePrefix1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.