Why are scala Collection.map and Try.map incompatible?

scala collection mapdocumentation says this in map:

Creates a new collection by applying a function to all elements of this list.

therefore, it works with every item in the collection.

but for verification, he says:

Displays the given function with the value from this Success or returns it if it is a failure.

therefore it only works on success, while I cannot understand anything to work on failure, I could still just print it. why is this incompatible with the collection map interface? I need to check what mapdoes for each data structure that I use, and can it behave differently?

+4
source share
1 answer

mapon any monadic structure always works for a "success case", i.e. where are the data you are interested in.

The List"case of success" is represented by its elements on the Trycase Success, at Futurethe same time, in the Optioncase Some.

List , " ", , Try, Future Option ( Nil )

, : , map -, , , " "

+7

All Articles