on master help sign in
Add camel case conversion example
9714d36Harendra Kumar
examples/CamelCase.hsnew file+32
@@ -0,0 +1,32 @@
1+-- Convert the input file to camel case and write to stdout
2+
3+import Data.Maybe (fromJust, isJust)
4+import System.Environment (getArgs)
5+import System.IO (Handle, IOMode(..), openFile, stdout)
6+
7+import qualified Streamly.Prelude as S
8+import qualified Streamly.Internal.FileSystem.Handle as FH
9+
10+camelCase :: Handle -> Handle -> IO ()
11+camelCase src dst =
12+ FH.fromStream dst
13+ $ S.map fromJust
14+ $ S.filter isJust
15+ $ S.map snd
16+ $ S.scanl' step (True, Nothing)
17+ $ FH.toStream src
18+
19+ where
20+
21+ step (wasSpace, _) x =
22+ if x == 0x0a || x >= 0x41 && x <= 0x5a
23+ then (False, Just x)
24+ else if x >= 0x61 && x <= 0x7a
25+ then (False, Just $ if wasSpace then x - 32 else x)
26+ else (True, Nothing)
27+
28+main :: IO ()
29+main = do
30+ name <- fmap head getArgs
31+ src <- openFile name ReadMode
32+ camelCase src stdout