On Friday, 7 October 2016 03:13:32 UTC+1, Dave Ford wrote: > > void myFunction(int x){ > if(x < 1){ > *throw new IllegalArgumentException("error: x must be >= 1"); * > } > return x * x * x; > } > > I look at runtime exceptions as a good thing. It's kind of like having two > returns. One return for the normal answer (return). And another for error > conditions (throw). >
myFunction : Int -> Result String Int myFunction = if x < 1 then Err "x must be >= 1" else Some x * x * x errorResult : Result String Int errorResult = Result.map (myFunction) (myFunction 0) -> Err "x must be >= 1" okResult : Result String Int okResult = Result.map (myFunction) (myFunction 2) -> Some 64 "Could have a string error" is kept with the type in the same way that "could throw IllegalArgumentException" is. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.