Positive position: the type variable is the result/output/range/codomain of the function Negative position: the type variable is the argument/input/domain of the function When a type variable appears in positive position, the data type is covariant with that variable. When the variable appears in negative position, the data type is contravariant with that variable.
flatMapout, it should all fit
Sumis in positive position (return type)
flatMapis a function that takes
f, so all of
fis in negative position, which makes
Bhave positive position and
Sumhave negative position
-1, they keep switching. Roughly speaking, functions of functions is the multiplication
List(1).withFilter(_ > 0) val res63: scala.collection.WithFilter[Int,[_]List[_]] = scala.collection.IterableOps$WithFilter@cf76c0b
def something(list: List[_]), then the
[_]is a wildcard, meaning you can pass a list value whose elements are any type.
[_]there means "i don't care what the type is, so i'm going to forget its name", just like
_in places like pattern matching means "i don't care what this is, i'm not even going to name it")
if you use cats you can follow the examples at https://typelevel.org/cats/typeclasses/parallel.html#parallel
basically you write your validation functions to produce
Either. but you "glue together" those functions to act using
Validated, which then gets converted back to
Either at the end
mapNfrom cats. it's like a mode: you switch from fail-fast (flatMap via Either) to collect-errors (mapN via Validated), and back.
val res63: scala.collection.WithFilter[Int, List] = ...to be correct
mapNalso does it.
[A]Foo[Int, String, A]- on this post about partial unification, so I guess it does have a specific meaning that I'm not familiar with