This commit is contained in:
Timofey Khoruzhii 2023-02-25 18:45:09 +03:00
parent 6e53baaa63
commit 3237af69e5

View file

@ -12,6 +12,7 @@ object task1_pattern_matching {
sealed trait Animal
task"Добавьте классы extends Animal такие, что бы могли быть определены закоментированные переменные ниже. Используйте тип Age для возраста, Weight для массы тела и Name для клички животного."
case class Cat(age: Age, mass: Weight) extends Animal
case class DogLike(mass: Weight, isForest: Boolean) extends Animal
@ -32,6 +33,7 @@ object task1_pattern_matching {
private val slim = (cat: Cat) => cat.mass <= 7
task"Заполните пробелы в pattern matching. Используйте для ограждения функции old и slim в случае кошек."
def matching(animal: Animal): String =
animal match {
case cat@Cat(_, _) if old(cat) && !slim(cat) => "Old fat cat"