The Traverse type class in Cats - Scala tutorial
Автор: Jakub Kozłowski
Загружено: 2019-09-15
Просмотров: 4470
Read the BTW at the end of the description!
In this video, you'll see what the Traverse type class is and what it allows you to do. You'll see some examples of traversable functors like List, Option and NonEmptyList, as well as applicative functors you can traverse to - IO, Option, Either, Validated and Map*.
Table of contents:
0:00 - Introduction, Traverse and `sequence`
0:41 - `Future.sequence` as a special case
3:46 - Traversing a list of IO with `sequence`
7:42 - Generalization of `sequence - `traverse`
9:28 - traversing non-lists - Traverse[Option]
10:00 - the intuition of what Traverse means
10:40 - traversing to different types
11:12 - sequencing a list of Option
12:48 - sequencing a list of Either
14:04 - accumulating failures with Validated
14:46 - NonEmptyList semigroup
15:50 - a word on the power of Traverse and guiding behavior by the instance of Applicative
17:07 - traversing with the Map applicative*
18:16 - NonEmptyTraverse and Apply - why we can still traverse with Map
21:32 - closing words
Read the code: https://github.com/kubukoz/videos/tre...
Previous videos:
Resource - • Resource composition in cats-effect with t...
Bracket - • Basic resource management with Bracket in ...
Blocker - • Using Blocker in cats-effect 1.4.0 - Scala...
Learn more about:
Traverse: https://typelevel.org/cats/typeclasse...
Applicative: https://typelevel.org/cats/typeclasse...
More traversals in a talk by Luka: • Luka Jacobovitz - TRAVERSALS FOR ALL OCCAS...
Traversing with Const: https://typelevel.org/cats/datatypes/...
*BTW*:
There's a small mistake in the video, irrelevant to traversals - `List.range(1, 10)` contains 9 elements, not 10 :)
Also, the file I work in is called ResourceDemo as it's a fork of the previous video's file - hopefully it doesn't bring much confusion.
- Map doesn't really have a full applicative but it has Apply, which is just Applicative without `pure`, so we can `nonEmptyTraverse` with it.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: