News for hackers. Stuff that matters.
Re:Functional Thinking after OO by lzm on Tuesday March 15, 2011 @12:38PM (#2328224)
How would you handle validation errors in this case?
Re:Functional Thinking after OO by CountSessine on Tuesday March 15, 2011 @01:22PM (#2328442)
It would be specifically handled by the return type from validateData and the argument to ProcessData. It sounds clunky, but with an algebraic data type it would be fairly clean - just another pattern to match in ProcessData.

For a simple example like this, that might be the cleanest solution. For anything more complicated (like recursive descent parsing), a processing chain like this is an ideal application for a monad, where the binding between functions would be customized to avoid calling ProcessData altogether.

Re:Functional Thinking after OO by lallysingh on Tuesday March 15, 2011 @01:10PM (#2328388)
Two ways: (1) (avoid) something similar to exceptions; (2) (much better) your datatype has an 'invalid' value. See Maybe in haskell, or Option in Scala (I think that last one's right...).
Re:Functional Thinking after OO by eru on Tuesday March 15, 2011 @02:04PM (#2328651)
With error handling in Haskell your code would look like

   getData = fetchDataFromSource =<< validateData =<< ProcessData
By the way, the original getData with (.) is backwards. It should be:

  getData = ProcessData . validateData . fetchDataFromSource