Re:Exploring the C# 6 Null Propagation Operator
by acjohnson55 on Sunday April 19, 2015 @02:44PM
(#9404258)
It's basically the same thing, except with that syntax, you have to label all the intermediate results
[ Parent
| on HN ]
Re:Exploring the C# 6 Null Propagation Operator
by bbcbasic on Sunday April 19, 2015 @05:06PM
(#9404874)
To avoid labeling:
routine :: Int -> Maybe Int
routine n = Just n >>= (divisorFilter 3) >>= (divisorFilter 2) >>= (divisorFilter 5)
-- Supporting function
divisorFilter :: Int -> Int -> Maybe Int
divisorFilter d n
| n `mod` d == 0 = Just n
| otherwise = Nothing
-- Using do syntax
routine' :: Int -> Maybe Int
routine' n = do
first <- divisorFilter 3 n
second <- divisorFilter 2 first
divisorFilter 5 second