Cats Core · Part 11
Cats Core, Part 9: Ior, for Results That Arrive with Warnings
Either holds an error or a value. Ior can hold both, which is what an import needs when a contract is accepted but something about it deserves a warning.
Tag
Cats Core · Part 11
Either holds an error or a value. Ior can hold both, which is what an import needs when a contract is accepted but something about it deserves a warning.
Cats Core · Part 10
Cats' Order gives you compare, min, max and sorting, and because it extends Eq, the fields you order by also decide what === treats as equal. I also explain why the standard library's .sorted needs .toOrdering, except when one particular import is in scope.
Cats Core · Part 9
Scala's == compares any two values, so a TodoId against a String compiles and returns false. Cats' Eq makes that a type error, explains why Some(1) === None fails, and lets me decide which fields count as equal.
Cats Core · Part 8
I wrote a tiny Todo validator with cats' ValidatedNec and it made one rule click: you can only accumulate errors when the steps don't depend on each other. That's the whole difference between an Applicative and a Monad.
Cats Core · Part 7
In Part 4 I wrote map[A, B](fa: Quote[A])(f: A => B) and moved on, but the letters kept slowing me down. A short break from new type classes: two rules that decode most Cats signatures, and the one name that breaks them.
Cats Core · Part 6
What the Nec in ValidatedNec guarantees, why errors.toList failed to compile in my Play controller, and when NonEmptyList is the better container.
Cats Core · Part 5
A price and a delivery cost are both optional, and nested map gives me Some(Some(15)). Apply combines independent values into one result, and Applicative adds the starting value a whole cart needs.
Cats Core · Part 4
List and Option already know how to map. I give my own Quote a Functor instance, reuse the same discount function, and trace why identity and composition matter.
Cats Core · Part 3
I knew how to combine two error reports. Monoid gives an empty batch a useful result, and foldMap takes the same idea to a shopping cart: turn each line into a contribution, then combine the totals.
Cats Core · Part 2
I could see Validated collecting errors, but I wanted to see the method call behind it. I made its Semigroup argument explicit, then supplied a combination rule for my own structured errors.