Since we don't want unused code around, this is already applied to Result.map2-5:
-- the following simplifications for map3 work for all Result.mapN
Result.map3 f (Ok a) (Ok b) (Ok c)
--> Ok (f a b c)
Result.map3 f (Ok a) (Err x) thirdResult
--> Err x
Result.map3 f firstResult (Err x) thirdResult
--> Result.map2 f firstResult (Err x)
includes all combinations with currying, for example
Result.map3 f firstResult (Err x)
--> always (Result.map2 f firstResult (Err x))
Result.map4 f firstResult (Err x)
--> (\_ _ -> Result.map2 f firstResult (Err x))
The same checks can be applied to Task, Json.Decode, Fuzz etc. with minimal effort.
Note that we don't simplify for example
Result.map2 (\a b -> a + b) firtResult (Ok second)
--> Result.map (\a -> a + second) firstResult
because some consider this a valid code style, e.g.
Result.map2 YourRecord
(Json.Decode.field "a" aDecoder)
(Json.Decode.succeed second)
(Json.Decode.field "c" cDecoder)
I personally disagree strongly but at the same time I'd prefer this to be a separate rule (the fixes are also not trivial, not sure we want to alter the existing code this much).
Since we don't want unused code around, this is already applied to
Result.map2-5
:includes all combinations with currying, for example
The same checks can be applied to
Task
,Json.Decode
,Fuzz
etc. with minimal effort.Note that we don't simplify for example
because some consider this a valid code style, e.g.
I personally disagree strongly but at the same time I'd prefer this to be a separate rule (the fixes are also not trivial, not sure we want to alter the existing code this much).