diff options
author | michaelt <what_is_it_to_do_anything@yahoo.com> | 2013-11-25 11:25:43 -0500 |
---|---|---|
committer | michaelt <what_is_it_to_do_anything@yahoo.com> | 2013-11-25 11:25:43 -0500 |
commit | ff38b9f029818b81f8e1c309f7eccc979ba5c346 (patch) | |
tree | 9d0c4d1185978f3e1065f6818274161fd9295dee /Pipes | |
parent | d4732515ee7ab5c5d5888fe3704e33c5b6ff16f9 (diff) | |
download | text-pipes-ff38b9f029818b81f8e1c309f7eccc979ba5c346.tar.gz text-pipes-ff38b9f029818b81f8e1c309f7eccc979ba5c346.tar.zst text-pipes-ff38b9f029818b81f8e1c309f7eccc979ba5c346.zip |
prophylactic RULEs for Pipes.maps
Diffstat (limited to 'Pipes')
-rw-r--r-- | Pipes/Text.hs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs index 06f2a7f..4fc6c4a 100644 --- a/Pipes/Text.hs +++ b/Pipes/Text.hs | |||
@@ -306,7 +306,7 @@ toHandle h = for cat (liftIO . T.hPutStr h) | |||
306 | {-# INLINABLE toHandle #-} | 306 | {-# INLINABLE toHandle #-} |
307 | 307 | ||
308 | {-# RULES "p >-> toHandle h" forall p h . | 308 | {-# RULES "p >-> toHandle h" forall p h . |
309 | p >-> toHandle h = for p (\bs -> liftIO (T.hPutStr h bs)) | 309 | p >-> toHandle h = for p (\txt -> liftIO (T.hPutStr h txt)) |
310 | #-} | 310 | #-} |
311 | 311 | ||
312 | 312 | ||
@@ -319,12 +319,19 @@ map :: (Monad m) => (Char -> Char) -> Pipe Text Text m r | |||
319 | map f = P.map (T.map f) | 319 | map f = P.map (T.map f) |
320 | {-# INLINABLE map #-} | 320 | {-# INLINABLE map #-} |
321 | 321 | ||
322 | {-# RULES "p >-> map f" forall p f . | ||
323 | p >-> map f = for p (\txt -> yield (T.map f txt)) | ||
324 | #-} | ||
325 | |||
322 | -- | Map a function over the characters of a text stream and concatenate the results | 326 | -- | Map a function over the characters of a text stream and concatenate the results |
323 | concatMap | 327 | concatMap |
324 | :: (Monad m) => (Char -> Text) -> Pipe Text Text m r | 328 | :: (Monad m) => (Char -> Text) -> Pipe Text Text m r |
325 | concatMap f = P.map (T.concatMap f) | 329 | concatMap f = P.map (T.concatMap f) |
326 | {-# INLINABLE concatMap #-} | 330 | {-# INLINABLE concatMap #-} |
327 | 331 | ||
332 | {-# RULES "p >-> concatMap f" forall p f . | ||
333 | p >-> concatMap f = for p (\txt -> yield (T.concatMap f txt)) | ||
334 | #-} | ||
328 | 335 | ||
329 | -- | Transform a Pipe of 'Text' into a Pipe of 'ByteString's using UTF-8 | 336 | -- | Transform a Pipe of 'Text' into a Pipe of 'ByteString's using UTF-8 |
330 | -- encoding; @encodeUtf8 = Pipes.Prelude.map TE.encodeUtf8@ so more complex | 337 | -- encoding; @encodeUtf8 = Pipes.Prelude.map TE.encodeUtf8@ so more complex |
@@ -333,16 +340,27 @@ encodeUtf8 :: Monad m => Pipe Text ByteString m r | |||
333 | encodeUtf8 = P.map TE.encodeUtf8 | 340 | encodeUtf8 = P.map TE.encodeUtf8 |
334 | {-# INLINEABLE encodeUtf8 #-} | 341 | {-# INLINEABLE encodeUtf8 #-} |
335 | 342 | ||
343 | {-# RULES "p >-> encodeUtf8" forall p . | ||
344 | p >-> encodeUtf8 = for p (\txt -> yield (TE.encodeUtf8 txt)) | ||
345 | #-} | ||
346 | |||
336 | -- | Transform a Pipe of 'String's into one of 'Text' chunks | 347 | -- | Transform a Pipe of 'String's into one of 'Text' chunks |
337 | pack :: Monad m => Pipe String Text m r | 348 | pack :: Monad m => Pipe String Text m r |
338 | pack = P.map T.pack | 349 | pack = P.map T.pack |
339 | {-# INLINEABLE pack #-} | 350 | {-# INLINEABLE pack #-} |
340 | 351 | ||
341 | -- | Transforma a Pipes of 'Text' chunks into one of 'String's | 352 | {-# RULES "p >-> pack" forall p . |
353 | p >-> pack = for p (\txt -> yield (T.pack txt)) | ||
354 | #-} | ||
355 | |||
356 | -- | Transform a Pipes of 'Text' chunks into one of 'String's | ||
342 | unpack :: Monad m => Pipe Text String m r | 357 | unpack :: Monad m => Pipe Text String m r |
343 | unpack = for cat (\t -> yield (T.unpack t)) | 358 | unpack = for cat (\t -> yield (T.unpack t)) |
344 | {-# INLINEABLE unpack #-} | 359 | {-# INLINEABLE unpack #-} |
345 | 360 | ||
361 | {-# RULES "p >-> unpack" forall p . | ||
362 | p >-> unpack = for p (\txt -> yield (T.unpack txt)) | ||
363 | #-} | ||
346 | 364 | ||
347 | -- | @toCaseFold@, @toLower@, @toUpper@ and @stripStart@ are standard 'Text' utility, | 365 | -- | @toCaseFold@, @toLower@, @toUpper@ and @stripStart@ are standard 'Text' utility, |
348 | -- here acting on a 'Text' pipe, rather as they would on a lazy text | 366 | -- here acting on a 'Text' pipe, rather as they would on a lazy text |
@@ -350,16 +368,29 @@ toCaseFold :: Monad m => Pipe Text Text m () | |||
350 | toCaseFold = P.map T.toCaseFold | 368 | toCaseFold = P.map T.toCaseFold |
351 | {-# INLINEABLE toCaseFold #-} | 369 | {-# INLINEABLE toCaseFold #-} |
352 | 370 | ||
371 | {-# RULES "p >-> toCaseFold" forall p . | ||
372 | p >-> toCaseFold = for p (\txt -> yield (T.toCaseFold txt)) | ||
373 | #-} | ||
374 | |||
375 | |||
353 | -- | lowercase incoming 'Text' | 376 | -- | lowercase incoming 'Text' |
354 | toLower :: Monad m => Pipe Text Text m () | 377 | toLower :: Monad m => Pipe Text Text m () |
355 | toLower = P.map T.toLower | 378 | toLower = P.map T.toLower |
356 | {-# INLINEABLE toLower #-} | 379 | {-# INLINEABLE toLower #-} |
357 | 380 | ||
381 | {-# RULES "p >-> toLower" forall p . | ||
382 | p >-> toLower = for p (\txt -> yield (T.toLower txt)) | ||
383 | #-} | ||
384 | |||
358 | -- | uppercase incoming 'Text' | 385 | -- | uppercase incoming 'Text' |
359 | toUpper :: Monad m => Pipe Text Text m () | 386 | toUpper :: Monad m => Pipe Text Text m () |
360 | toUpper = P.map T.toUpper | 387 | toUpper = P.map T.toUpper |
361 | {-# INLINEABLE toUpper #-} | 388 | {-# INLINEABLE toUpper #-} |
362 | 389 | ||
390 | {-# RULES "p >-> toUpper" forall p . | ||
391 | p >-> toUpper = for p (\txt -> yield (T.toUpper txt)) | ||
392 | #-} | ||
393 | |||
363 | -- | Remove leading white space from an incoming succession of 'Text's | 394 | -- | Remove leading white space from an incoming succession of 'Text's |
364 | stripStart :: Monad m => Pipe Text Text m r | 395 | stripStart :: Monad m => Pipe Text Text m r |
365 | stripStart = do | 396 | stripStart = do |
@@ -432,7 +463,10 @@ filter :: (Monad m) => (Char -> Bool) -> Pipe Text Text m r | |||
432 | filter predicate = P.map (T.filter predicate) | 463 | filter predicate = P.map (T.filter predicate) |
433 | {-# INLINABLE filter #-} | 464 | {-# INLINABLE filter #-} |
434 | 465 | ||
435 | 466 | {-# RULES "p >-> filter q" forall p q . | |
467 | p >-> filter q = for p (\txt -> yield (T.filter q txt)) | ||
468 | #-} | ||
469 | |||
436 | -- | Strict left scan over the characters | 470 | -- | Strict left scan over the characters |
437 | scan | 471 | scan |
438 | :: (Monad m) | 472 | :: (Monad m) |