Most (all?) RemoteData implementations provide a map function helps reduce the boilerplate code you’re referring to. It’s used like so:
import RemoteData exposing (RemoteData(..))
Success "Bob"
|> RemoteData.map (\name -> "Hello, " ++ name)
|> toString
--> Success "Hello, Bob"
Failure "Something went wrong"
|> RemoteData.map (\name -> "Hello, " ++ name)
|> toString
--> Failure "Something went wrong"
map is basically a shortcut to say “please run this function on this data, if the data is in a ‘success’ state”. map is provided for many data types, for example, Maybe.map and Task.map. And also for types like Cmd.map, where there’s not a ‘success’ state, but it can be useful to access the internal value.
Hopefully that makes sense
. I could create another example with more context if that would help.