Programming with Functions #4 - unapply and newtype

preview_player
Показать описание
Design your code around your cats.
Data.
I mean data.

Background music:
Winter Night, Summer Day by Beluga Ten (c) copyright 2019
Licensed under a Creative Commons Attribution Noncommercial (3.0) license.

Cat's eyes:
Рекомендации по теме
Комментарии
Автор

Very very cool video. I think it's better than live coding.

avalagum
Автор

Cool video!

A couple of minor notes:

1. You can mark an unapply method to return a Some[A] instead of Option[A] such that the compiler knows it will always match, this is really useful now that since 2.13.x (can't remember in which version it was) the compiler is more strict with exhaustive warnings.

2. Using AnyVal for newtypes is a bad idea, not only because you can not extend other traits, but because they may box _(and then unbox)_ multiple times if you are not careful. As such, most people recommend only using AnyVal for extension methods or the partially-applied type trick.
Thankfully we have scala-newtype and Scala 3 will have opaque types.

luismiguelmejiasuarez
visit shbcf.ru