/usr/share/doc/libghc-conduit-doc/html/conduit.txt is in libghc-conduit-doc 1.0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 | -- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Streaming data processing library.
--
-- <tt>conduit</tt> is a solution to the streaming data problem, allowing
-- for production, transformation, and consumption of streams of data in
-- constant memory. It is an alternative to lazy I/O which guarantees
-- deterministic resource handling, and fits in the same general solution
-- space as <tt>enumerator</tt>/<tt>iteratee</tt> and <tt>pipes</tt>. For
-- a tutorial, please visit
-- <a>https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview</a>.
--
-- Release history:
--
-- <ul>
-- <li><i>1.0</i> Simplified the user-facing interface back to the
-- Source, Sink, and Conduit types, with Producer and Consumer for
-- generic code. Error messages have been simplified, and optional
-- leftovers and upstream terminators have been removed from the external
-- API. Some long-deprecated functions were finally removed.</li>
-- <li><i>0.5</i> The internals of the package are now separated to the
-- .Internal module, leaving only the higher-level interface in the
-- advertised API. Internally, switched to a <tt>Leftover</tt>
-- constructor and slightly tweaked the finalization semantics.</li>
-- <li><i>0.4</i> Inspired by the design of the pipes package: we now
-- have a single unified type underlying <tt>Source</tt>, <tt>Sink</tt>,
-- and <tt>Conduit</tt>. This type is named <tt>Pipe</tt>. There are type
-- synonyms provided for the other three types. Additionally,
-- <tt>BufferedSource</tt> is no longer provided. Instead, the
-- connect-and-resume operator, <tt>$$+</tt>, can be used for the same
-- purpose.</li>
-- <li><i>0.3</i> ResourceT has been greatly simplified, specialized for
-- IO, and moved into a separate package. Instead of hard-coding
-- ResourceT into the conduit datatypes, they can now live around any
-- monad. The Conduit datatype has been enhanced to better allow
-- generation of streaming output. The SourceResult, SinkResult, and
-- ConduitResult datatypes have been removed entirely.</li>
-- <li><i>0.2</i> Instead of storing state in mutable variables, we now
-- use CPS. A <tt>Source</tt> returns the next <tt>Source</tt>, and
-- likewise for <tt>Sink</tt>s and <tt>Conduit</tt>s. Not only does this
-- take better advantage of GHC's optimizations (about a 20% speedup),
-- but it allows some operations to have a reduction in algorithmic
-- complexity from exponential to linear. This also allowed us to remove
-- the <tt>Prepared</tt> set of types. Also, the <tt>State</tt> functions
-- (e.g., <tt>sinkState</tt>) use better constructors for return types,
-- avoiding the need for a dummy state on completion.</li>
-- <li><i>0.1</i> <tt>BufferedSource</tt> is now an abstract type, and
-- has a much more efficient internal representation. The result was a
-- 41% speedup on microbenchmarks (note: do not expect speedups anywhere
-- near that in real usage). In general, we are moving towards
-- <tt>BufferedSource</tt> being a specific tool used internally as
-- needed, but using <tt>Source</tt> for all external APIs.</li>
-- <li><i>0.0</i> Initial release.</li>
-- </ul>
@package conduit
@version 1.0.13
module Data.Conduit.Internal
-- | The underlying datatype for all the types in this package. In has six
-- type parameters:
--
-- <ul>
-- <li><i>l</i> is the type of values that may be left over from this
-- <tt>Pipe</tt>. A <tt>Pipe</tt> with no leftovers would use
-- <tt>Void</tt> here, and one with leftovers would use the same type as
-- the <i>i</i> parameter. Leftovers are automatically provided to the
-- next <tt>Pipe</tt> in the monadic chain.</li>
-- <li><i>i</i> is the type of values for this <tt>Pipe</tt>'s input
-- stream.</li>
-- <li><i>o</i> is the type of values for this <tt>Pipe</tt>'s output
-- stream.</li>
-- <li><i>u</i> is the result type from the upstream <tt>Pipe</tt>.</li>
-- <li><i>m</i> is the underlying monad.</li>
-- <li><i>r</i> is the result type.</li>
-- </ul>
--
-- A basic intuition is that every <tt>Pipe</tt> produces a stream of
-- output values (<i>o</i>), and eventually indicates that this stream is
-- terminated by sending a result (<i>r</i>). On the receiving end of a
-- <tt>Pipe</tt>, these become the <i>i</i> and <i>u</i> parameters.
--
-- Since 0.5.0
data Pipe l i o u m r
-- | Provide new output to be sent downstream. This constructor has three
-- fields: the next <tt>Pipe</tt> to be used, a finalization function,
-- and the output value.
HaveOutput :: (Pipe l i o u m r) -> (m ()) -> o -> Pipe l i o u m r
-- | Request more input from upstream. The first field takes a new input
-- value and provides a new <tt>Pipe</tt>. The second takes an upstream
-- result value, which indicates that upstream is producing no more
-- results.
NeedInput :: (i -> Pipe l i o u m r) -> (u -> Pipe l i o u m r) -> Pipe l i o u m r
-- | Processing with this <tt>Pipe</tt> is complete, providing the final
-- result.
Done :: r -> Pipe l i o u m r
-- | Require running of a monadic action to get the next <tt>Pipe</tt>.
PipeM :: (m (Pipe l i o u m r)) -> Pipe l i o u m r
-- | Return leftover input, which should be provided to future operations.
Leftover :: (Pipe l i o u m r) -> l -> Pipe l i o u m r
-- | Core datatype of the conduit package. This type represents a general
-- component which can consume a stream of input values <tt>i</tt>,
-- produce a stream of output values <tt>o</tt>, perform actions in the
-- <tt>m</tt> monad, and produce a final result <tt>r</tt>. The type
-- synonyms provided here are simply wrappers around this type.
--
-- Since 1.0.0
newtype ConduitM i o m r
ConduitM :: Pipe i i o () m r -> ConduitM i o m r
unConduitM :: ConduitM i o m r -> Pipe i i o () m r
-- | Provides a stream of output values, without consuming any input or
-- producing a final result.
--
-- Since 0.5.0
type Source m o = ConduitM () o m ()
-- | A component which produces a stream of output values, regardless of
-- the input stream. A <tt>Producer</tt> is a generalization of a
-- <tt>Source</tt>, and can be used as either a <tt>Source</tt> or a
-- <tt>Conduit</tt>.
--
-- Since 1.0.0
type Producer m o = forall i. ConduitM i o m ()
-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
--
-- <pre>
-- type Sink i m r = ConduitM i Void m r
-- </pre>
--
-- Since 0.5.0
type Sink i = ConduitM i Void
-- | A component which consumes a stream of input values and produces a
-- final result, regardless of the output stream. A <tt>Consumer</tt> is
-- a generalization of a <tt>Sink</tt>, and can be used as either a
-- <tt>Sink</tt> or a <tt>Conduit</tt>.
--
-- Since 1.0.0
type Consumer i m r = forall o. ConduitM i o m r
-- | Consumes a stream of input values and produces a stream of output
-- values, without producing a final result.
--
-- Since 0.5.0
type Conduit i m o = ConduitM i o m ()
-- | A <tt>Source</tt> which has been started, but has not yet completed.
--
-- This type contains both the current state of the <tt>Source</tt>, and
-- the finalizer to be run to close it.
--
-- Since 0.5.0
data ResumableSource m o
ResumableSource :: (Source m o) -> (m ()) -> ResumableSource m o
-- | Wait for a single input value from upstream.
--
-- Since 0.5.0
await :: Pipe l i o u m (Maybe i)
-- | This is similar to <tt>await</tt>, but will return the upstream result
-- value as <tt>Left</tt> if available.
--
-- Since 0.5.0
awaitE :: Pipe l i o u m (Either u i)
-- | Wait for input forever, calling the given inner <tt>Pipe</tt> for each
-- piece of new input. Returns the upstream result type.
--
-- Since 0.5.0
awaitForever :: Monad m => (i -> Pipe l i o r m r') -> Pipe l i o r m r
-- | Send a single output value downstream. If the downstream <tt>Pipe</tt>
-- terminates, this <tt>Pipe</tt> will terminate as well.
--
-- Since 0.5.0
yield :: Monad m => o -> Pipe l i o u m ()
-- | Similar to <tt>yield</tt>, but additionally takes a finalizer to be
-- run if the downstream <tt>Pipe</tt> terminates.
--
-- Since 0.5.0
yieldOr :: Monad m => o -> m () -> Pipe l i o u m ()
-- | Provide a single piece of leftover input to be consumed by the next
-- pipe in the current monadic binding.
--
-- <i>Note</i>: it is highly encouraged to only return leftover values
-- from input already consumed from upstream.
--
-- Since 0.5.0
leftover :: l -> Pipe l i o u m ()
-- | Perform some allocation and run an inner <tt>Pipe</tt>. Two guarantees
-- are given about resource finalization:
--
-- <ol>
-- <li>It will be <i>prompt</i>. The finalization will be run as early as
-- possible.</li>
-- <li>It is exception safe. Due to usage of <tt>resourcet</tt>, the
-- finalization will be run in the event of any exceptions.</li>
-- </ol>
--
-- Since 0.5.0
bracketP :: MonadResource m => IO a -> (a -> IO ()) -> (a -> Pipe l i o u m r) -> Pipe l i o u m r
-- | Add some code to be run when the given <tt>Pipe</tt> cleans up.
--
-- Since 0.4.1
addCleanup :: Monad m => (Bool -> m ()) -> Pipe l i o u m r -> Pipe l i o u m r
-- | The identity <tt>Pipe</tt>.
--
-- Since 0.5.0
idP :: Monad m => Pipe l a a r m r
-- | Compose a left and right pipe together into a complete pipe. The left
-- pipe will be automatically closed when the right pipe finishes.
--
-- Since 0.5.0
pipe :: Monad m => Pipe l a b r0 m r1 -> Pipe Void b c r1 m r2 -> Pipe l a c r0 m r2
-- | Same as <a>pipe</a>, but automatically applies <a>injectLeftovers</a>
-- to the right <tt>Pipe</tt>.
--
-- Since 0.5.0
pipeL :: Monad m => Pipe l a b r0 m r1 -> Pipe b b c r1 m r2 -> Pipe l a c r0 m r2
-- | Connect a <tt>Source</tt> to a <tt>Sink</tt> until the latter closes.
-- Returns both the most recent state of the <tt>Source</tt> and the
-- result of the <tt>Sink</tt>.
--
-- We use a <tt>ResumableSource</tt> to keep track of the most recent
-- finalizer provided by the <tt>Source</tt>.
--
-- Since 0.5.0
connectResume :: Monad m => ResumableSource m o -> Sink o m r -> m (ResumableSource m o, r)
-- | Run a pipeline until processing completes.
--
-- Since 0.5.0
runPipe :: Monad m => Pipe Void () Void () m r -> m r
-- | Transforms a <tt>Pipe</tt> that provides leftovers to one which does
-- not, allowing it to be composed.
--
-- This function will provide any leftover values within this
-- <tt>Pipe</tt> to any calls to <tt>await</tt>. If there are more
-- leftover values than are demanded, the remainder are discarded.
--
-- Since 0.5.0
injectLeftovers :: Monad m => Pipe i i o u m r -> Pipe l i o u m r
-- | Fuse together two <tt>Pipe</tt>s, connecting the output from the left
-- to the input of the right.
--
-- Notice that the <i>leftover</i> parameter for the <tt>Pipe</tt>s must
-- be <tt>Void</tt>. This ensures that there is no accidental data loss
-- of leftovers during fusion. If you have a <tt>Pipe</tt> with
-- leftovers, you must first call <a>injectLeftovers</a>.
--
-- Since 0.5.0
(>+>) :: Monad m => Pipe l a b r0 m r1 -> Pipe Void b c r1 m r2 -> Pipe l a c r0 m r2
-- | Same as <a>>+></a>, but reverse the order of the arguments.
--
-- Since 0.5.0
(<+<) :: Monad m => Pipe Void b c r1 m r2 -> Pipe l a b r0 m r1 -> Pipe l a c r0 m r2
sourceToPipe :: Monad m => Source m o -> Pipe l i o u m ()
sinkToPipe :: Monad m => Sink i m r -> Pipe l i o u m r
conduitToPipe :: Monad m => Conduit i m o -> Pipe l i o u m ()
-- | Generalize a <a>Source</a> to a <a>Producer</a>.
--
-- Since 1.0.0
toProducer :: Monad m => Source m a -> Producer m a
-- | Generalize a <a>Sink</a> to a <a>Consumer</a>.
--
-- Since 1.0.0
toConsumer :: Monad m => Sink a m b -> Consumer a m b
-- | See <a>catchC</a> for more details.
--
-- Since 1.0.11
catchP :: (MonadBaseControl IO m, Exception e) => Pipe l i o u m r -> (e -> Pipe l i o u m r) -> Pipe l i o u m r
-- | The same as <tt>flip catchP</tt>.
--
-- Since 1.0.11
handleP :: (MonadBaseControl IO m, Exception e) => (e -> Pipe l i o u m r) -> Pipe l i o u m r -> Pipe l i o u m r
-- | See <a>tryC</a> for more details.
--
-- Since 1.0.11
tryP :: (MonadBaseControl IO m, Exception e) => Pipe l i o u m r -> Pipe l i o u m (Either e r)
-- | Catch all exceptions thrown by the current component of the pipeline.
--
-- Note: this will <i>not</i> catch exceptions thrown by other
-- components! For example, if an exception is thrown in a
-- <tt>Source</tt> feeding to a <tt>Sink</tt>, and the <tt>Sink</tt> uses
-- <tt>catchC</tt>, the exception will <i>not</i> be caught.
--
-- Due to this behavior (as well as lack of async exception handling),
-- you should not try to implement combinators such as
-- <tt>onException</tt> in terms of this primitive function.
--
-- Note also that the exception handling will <i>not</i> be applied to
-- any finalizers generated by this conduit.
--
-- Since 1.0.11
catchC :: (MonadBaseControl IO m, Exception e) => ConduitM i o m r -> (e -> ConduitM i o m r) -> ConduitM i o m r
-- | The same as <tt>flip catchC</tt>.
--
-- Since 1.0.11
handleC :: (MonadBaseControl IO m, Exception e) => (e -> ConduitM i o m r) -> ConduitM i o m r -> ConduitM i o m r
-- | A version of <tt>try</tt> for use within a pipeline. See the comments
-- in <tt>catchC</tt> for more details.
--
-- Since 1.0.11
tryC :: (MonadBaseControl IO m, Exception e) => ConduitM i o m r -> ConduitM i o m (Either e r)
-- | Transform the monad that a <tt>Pipe</tt> lives in.
--
-- Note that the monad transforming function will be run multiple times,
-- resulting in unintuitive behavior in some cases. For a fuller
-- treatment, please see:
--
--
-- <a>https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers</a>
--
-- This function is just a synonym for <a>hoist</a>.
--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> Pipe l i o u m r -> Pipe l i o u n r
-- | Apply a function to all the output values of a <tt>Pipe</tt>.
--
-- This mimics the behavior of <a>fmap</a> for a <a>Source</a> and
-- <a>Conduit</a> in pre-0.4 days.
--
-- Since 0.4.1
mapOutput :: Monad m => (o1 -> o2) -> Pipe l i o1 u m r -> Pipe l i o2 u m r
-- | Same as <a>mapOutput</a>, but use a function that returns
-- <tt>Maybe</tt> values.
--
-- Since 0.5.0
mapOutputMaybe :: Monad m => (o1 -> Maybe o2) -> Pipe l i o1 u m r -> Pipe l i o2 u m r
-- | Apply a function to all the input values of a <tt>Pipe</tt>.
--
-- Since 0.5.0
mapInput :: Monad m => (i1 -> i2) -> (l2 -> Maybe l1) -> Pipe l2 i2 o u m r -> Pipe l1 i1 o u m r
-- | Convert a list into a source.
--
-- Since 0.3.0
sourceList :: Monad m => [a] -> Pipe l i a u m ()
-- | Returns a tuple of the upstream and downstream results. Note that this
-- will force consumption of the entire input stream.
--
-- Since 0.5.0
withUpstream :: Monad m => Pipe l i o u m r -> Pipe l i o u m (u, r)
-- | Unwraps a <tt>ResumableSource</tt> into a <tt>Source</tt> and a
-- finalizer.
--
-- A <tt>ResumableSource</tt> represents a <tt>Source</tt> which has
-- already been run, and therefore has a finalizer registered. As a
-- result, if we want to turn it into a regular <tt>Source</tt>, we need
-- to ensure that the finalizer will be run appropriately. By
-- appropriately, I mean:
--
-- <ul>
-- <li>If a new finalizer is registered, the old one should not be
-- called.</li>
-- <li>If the old one is called, it should not be called again.</li>
-- </ul>
--
-- This function returns both a <tt>Source</tt> and a finalizer which
-- ensures that the above two conditions hold. Once you call that
-- finalizer, the <tt>Source</tt> is invalidated and cannot be used.
--
-- Since 0.5.2
unwrapResumable :: MonadIO m => ResumableSource m o -> m (Source m o, m ())
enumFromTo :: (Enum o, Eq o, Monad m) => o -> o -> Pipe l i o u m ()
-- | Combines two sinks. The new sink will complete when both input sinks
-- have completed.
--
-- Any leftovers are discarded.
--
-- Since 0.4.1
zipSinks :: Monad m => Sink i m r -> Sink i m r' -> Sink i m (r, r')
-- | Combines two sources. The new source will stop producing once either
-- source has been exhausted.
--
-- Since 1.0.13
zipSources :: Monad m => Source m a -> Source m b -> Source m (a, b)
-- | Combines two sources. The new source will stop producing once either
-- source has been exhausted.
--
-- Since 1.0.13
zipSourcesApp :: Monad m => Source m (a -> b) -> Source m a -> Source m b
instance Monad m => Functor (ConduitM i o m)
instance Monad m => Applicative (ConduitM i o m)
instance Monad m => Monad (ConduitM i o m)
instance MonadIO m => MonadIO (ConduitM i o m)
instance MonadTrans (ConduitM i o)
instance MonadThrow m => MonadThrow (ConduitM i o m)
instance MonadActive m => MonadActive (ConduitM i o m)
instance MonadResource m => MonadResource (ConduitM i o m)
instance MFunctor (ConduitM i o)
instance MFunctor (Pipe l i o u)
instance MFunctor ResumableSource
instance Monad m => Monoid (ConduitM i o m ())
instance MonadBase base m => MonadBase base (ConduitM i o m)
instance MonadError e m => MonadError e (ConduitM i o m)
instance MonadRWS r w s m => MonadRWS r w s (ConduitM i o m)
instance MonadState s m => MonadState s (ConduitM i o m)
instance MonadWriter w m => MonadWriter w (ConduitM i o m)
instance MonadReader r m => MonadReader r (ConduitM i o m)
instance MonadError e m => MonadError e (Pipe l i o u m)
instance MonadRWS r w s m => MonadRWS r w s (Pipe l i o u m)
instance MonadState s m => MonadState s (Pipe l i o u m)
instance MonadWriter w m => MonadWriter w (Pipe l i o u m)
instance MonadReader r m => MonadReader r (Pipe l i o u m)
instance MonadResource m => MonadResource (Pipe l i o u m)
instance Monad m => Monoid (Pipe l i o u m ())
instance MonadActive m => MonadActive (Pipe l i o u m)
instance MonadThrow m => MonadThrow (Pipe l i o u m)
instance MonadIO m => MonadIO (Pipe l i o u m)
instance MonadTrans (Pipe l i o u)
instance MonadBase base m => MonadBase base (Pipe l i o u m)
instance Monad m => Monad (Pipe l i o u m)
instance Monad m => Applicative (Pipe l i o u m)
instance Monad m => Functor (Pipe l i o u m)
-- | Various utility functions versions of <tt>conduit</tt>.
module Data.Conduit.Util
-- | Deprecated synonym for <a>zipSources</a>.
--
-- Since 0.3.0
-- | <i>Deprecated: Use zipSources instead </i>
zip :: Monad m => Source m a -> Source m b -> Source m (a, b)
-- | Combines two sources. The new source will stop producing once either
-- source has been exhausted.
--
-- Since 1.0.13
zipSources :: Monad m => Source m a -> Source m b -> Source m (a, b)
-- | Combines two sinks. The new sink will complete when both input sinks
-- have completed.
--
-- Any leftovers are discarded.
--
-- Since 0.4.1
zipSinks :: Monad m => Sink i m r -> Sink i m r' -> Sink i m (r, r')
-- | Turn a <tt>Sink</tt> into a <tt>Conduit</tt> in the following way:
--
-- <ul>
-- <li>All input passed to the <tt>Sink</tt> is yielded downstream.</li>
-- <li>When the <tt>Sink</tt> finishes processing, the result is passed
-- to the provided to the finalizer function.</li>
-- </ul>
--
-- Note that the <tt>Sink</tt> will stop receiving input as soon as the
-- downstream it is connected to shuts down.
--
-- An example usage would be to write the result of a <tt>Sink</tt> to
-- some mutable variable while allowing other processing to continue.
--
-- Since 1.0.10
passthroughSink :: Monad m => Sink i m r -> (r -> m ()) -> Conduit i m i
-- | If this is your first time with conduit, you should probably start
-- with the tutorial:
-- <a>https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview</a>.
module Data.Conduit
-- | Provides a stream of output values, without consuming any input or
-- producing a final result.
--
-- Since 0.5.0
type Source m o = ConduitM () o m ()
-- | Consumes a stream of input values and produces a stream of output
-- values, without producing a final result.
--
-- Since 0.5.0
type Conduit i m o = ConduitM i o m ()
-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
--
-- <pre>
-- type Sink i m r = ConduitM i Void m r
-- </pre>
--
-- Since 0.5.0
type Sink i = ConduitM i Void
-- | Core datatype of the conduit package. This type represents a general
-- component which can consume a stream of input values <tt>i</tt>,
-- produce a stream of output values <tt>o</tt>, perform actions in the
-- <tt>m</tt> monad, and produce a final result <tt>r</tt>. The type
-- synonyms provided here are simply wrappers around this type.
--
-- Since 1.0.0
data ConduitM i o m r
-- | The connect operator, which pulls data from a source and pushes to a
-- sink. If you would like to keep the <tt>Source</tt> open to be used
-- for other operations, use the connect-and-resume operator <a>$$+</a>.
--
-- Since 0.4.0
($$) :: Monad m => Source m a -> Sink a m b -> m b
-- | Left fuse, combining a source and a conduit together into a new
-- source.
--
-- Both the <tt>Source</tt> and <tt>Conduit</tt> will be closed when the
-- newly-created <tt>Source</tt> is closed.
--
-- Leftover data from the <tt>Conduit</tt> will be discarded.
--
-- Since 0.4.0
($=) :: Monad m => Source m a -> Conduit a m b -> Source m b
-- | Right fuse, combining a conduit and a sink together into a new sink.
--
-- Both the <tt>Conduit</tt> and <tt>Sink</tt> will be closed when the
-- newly-created <tt>Sink</tt> is closed.
--
-- Leftover data returned from the <tt>Sink</tt> will be discarded.
--
-- Since 0.4.0
(=$) :: Monad m => Conduit a m b -> Sink b m c -> Sink a m c
-- | Fusion operator, combining two <tt>Conduit</tt>s together into a new
-- <tt>Conduit</tt>.
--
-- Both <tt>Conduit</tt>s will be closed when the newly-created
-- <tt>Conduit</tt> is closed.
--
-- Leftover data returned from the right <tt>Conduit</tt> will be
-- discarded.
--
-- Since 0.4.0
(=$=) :: Monad m => Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
-- | Wait for a single input value from upstream. If no data is available,
-- returns <tt>Nothing</tt>.
--
-- Since 0.5.0
await :: Monad m => Consumer i m (Maybe i)
-- | Send a value downstream to the next component to consume. If the
-- downstream component terminates, this call will never return control.
-- If you would like to register a cleanup function, please use
-- <a>yieldOr</a> instead.
--
-- Since 0.5.0
yield :: Monad m => o -> ConduitM i o m ()
-- | Provide a single piece of leftover input to be consumed by the next
-- component in the current monadic binding.
--
-- <i>Note</i>: it is highly encouraged to only return leftover values
-- from input already consumed from upstream.
--
-- Since 0.5.0
leftover :: i -> ConduitM i o m ()
-- | Perform some allocation and run an inner component. Two guarantees are
-- given about resource finalization:
--
-- <ol>
-- <li>It will be <i>prompt</i>. The finalization will be run as early as
-- possible.</li>
-- <li>It is exception safe. Due to usage of <tt>resourcet</tt>, the
-- finalization will be run in the event of any exceptions.</li>
-- </ol>
--
-- Since 0.5.0
bracketP :: MonadResource m => IO a -> (a -> IO ()) -> (a -> ConduitM i o m r) -> ConduitM i o m r
-- | Add some code to be run when the given component cleans up.
--
-- The supplied cleanup function will be given a <tt>True</tt> if the
-- component ran to completion, or <tt>False</tt> if it terminated early
-- due to a downstream component terminating.
--
-- Note that this function is not exception safe. For that, please use
-- <a>bracketP</a>.
--
-- Since 0.4.1
addCleanup :: Monad m => (Bool -> m ()) -> ConduitM i o m r -> ConduitM i o m r
-- | Similar to <a>yield</a>, but additionally takes a finalizer to be run
-- if the downstream component terminates.
--
-- Since 0.5.0
yieldOr :: Monad m => o -> m () -> ConduitM i o m ()
-- | Catch all exceptions thrown by the current component of the pipeline.
--
-- Note: this will <i>not</i> catch exceptions thrown by other
-- components! For example, if an exception is thrown in a
-- <tt>Source</tt> feeding to a <tt>Sink</tt>, and the <tt>Sink</tt> uses
-- <tt>catchC</tt>, the exception will <i>not</i> be caught.
--
-- Due to this behavior (as well as lack of async exception handling),
-- you should not try to implement combinators such as
-- <tt>onException</tt> in terms of this primitive function.
--
-- Note also that the exception handling will <i>not</i> be applied to
-- any finalizers generated by this conduit.
--
-- Since 1.0.11
catchC :: (MonadBaseControl IO m, Exception e) => ConduitM i o m r -> (e -> ConduitM i o m r) -> ConduitM i o m r
-- | The same as <tt>flip catchC</tt>.
--
-- Since 1.0.11
handleC :: (MonadBaseControl IO m, Exception e) => (e -> ConduitM i o m r) -> ConduitM i o m r -> ConduitM i o m r
-- | A version of <tt>try</tt> for use within a pipeline. See the comments
-- in <tt>catchC</tt> for more details.
--
-- Since 1.0.11
tryC :: (MonadBaseControl IO m, Exception e) => ConduitM i o m r -> ConduitM i o m (Either e r)
-- | A component which produces a stream of output values, regardless of
-- the input stream. A <tt>Producer</tt> is a generalization of a
-- <tt>Source</tt>, and can be used as either a <tt>Source</tt> or a
-- <tt>Conduit</tt>.
--
-- Since 1.0.0
type Producer m o = forall i. ConduitM i o m ()
-- | A component which consumes a stream of input values and produces a
-- final result, regardless of the output stream. A <tt>Consumer</tt> is
-- a generalization of a <tt>Sink</tt>, and can be used as either a
-- <tt>Sink</tt> or a <tt>Conduit</tt>.
--
-- Since 1.0.0
type Consumer i m r = forall o. ConduitM i o m r
-- | Generalize a <a>Source</a> to a <a>Producer</a>.
--
-- Since 1.0.0
toProducer :: Monad m => Source m a -> Producer m a
-- | Generalize a <a>Sink</a> to a <a>Consumer</a>.
--
-- Since 1.0.0
toConsumer :: Monad m => Sink a m b -> Consumer a m b
-- | Wait for input forever, calling the given inner component for each
-- piece of new input. Returns the upstream result type.
--
-- This function is provided as a convenience for the common pattern of
-- <tt>await</tt>ing input, checking if it's <tt>Just</tt> and then
-- looping.
--
-- Since 0.5.0
awaitForever :: Monad m => (i -> ConduitM i o m r) -> ConduitM i o m ()
-- | Transform the monad that a <tt>ConduitM</tt> lives in.
--
-- Note that the monad transforming function will be run multiple times,
-- resulting in unintuitive behavior in some cases. For a fuller
-- treatment, please see:
--
--
-- <a>https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers</a>
--
-- This function is just a synonym for <a>hoist</a>.
--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> ConduitM i o m r -> ConduitM i o n r
-- | Apply a function to all the output values of a <tt>ConduitM</tt>.
--
-- This mimics the behavior of <a>fmap</a> for a <a>Source</a> and
-- <a>Conduit</a> in pre-0.4 days. It can also be simulated by fusing
-- with the <tt>map</tt> conduit from <a>Data.Conduit.List</a>.
--
-- Since 0.4.1
mapOutput :: Monad m => (o1 -> o2) -> ConduitM i o1 m r -> ConduitM i o2 m r
-- | Same as <a>mapOutput</a>, but use a function that returns
-- <tt>Maybe</tt> values.
--
-- Since 0.5.0
mapOutputMaybe :: Monad m => (o1 -> Maybe o2) -> ConduitM i o1 m r -> ConduitM i o2 m r
-- | Apply a function to all the input values of a <tt>ConduitM</tt>.
--
-- Since 0.5.0
mapInput :: Monad m => (i1 -> i2) -> (i2 -> Maybe i1) -> ConduitM i2 o m r -> ConduitM i1 o m r
-- | A <tt>Source</tt> which has been started, but has not yet completed.
--
-- This type contains both the current state of the <tt>Source</tt>, and
-- the finalizer to be run to close it.
--
-- Since 0.5.0
data ResumableSource m o
-- | The connect-and-resume operator. This does not close the
-- <tt>Source</tt>, but instead returns it to be used again. This allows
-- a <tt>Source</tt> to be used incrementally in a large program, without
-- forcing the entire program to live in the <tt>Sink</tt> monad.
--
-- Mnemonic: connect + do more.
--
-- Since 0.5.0
($$+) :: Monad m => Source m a -> Sink a m b -> m (ResumableSource m a, b)
-- | Continue processing after usage of <tt>$$+</tt>.
--
-- Since 0.5.0
($$++) :: Monad m => ResumableSource m a -> Sink a m b -> m (ResumableSource m a, b)
-- | Complete processing of a <tt>ResumableSource</tt>. This will run the
-- finalizer associated with the <tt>ResumableSource</tt>. In order to
-- guarantee process resource finalization, you <i>must</i> use this
-- operator after using <tt>$$+</tt> and <tt>$$++</tt>.
--
-- Since 0.5.0
($$+-) :: Monad m => ResumableSource m a -> Sink a m b -> m b
-- | Unwraps a <tt>ResumableSource</tt> into a <tt>Source</tt> and a
-- finalizer.
--
-- A <tt>ResumableSource</tt> represents a <tt>Source</tt> which has
-- already been run, and therefore has a finalizer registered. As a
-- result, if we want to turn it into a regular <tt>Source</tt>, we need
-- to ensure that the finalizer will be run appropriately. By
-- appropriately, I mean:
--
-- <ul>
-- <li>If a new finalizer is registered, the old one should not be
-- called.</li>
-- <li>If the old one is called, it should not be called again.</li>
-- </ul>
--
-- This function returns both a <tt>Source</tt> and a finalizer which
-- ensures that the above two conditions hold. Once you call that
-- finalizer, the <tt>Source</tt> is invalidated and cannot be used.
--
-- Since 0.5.2
unwrapResumable :: MonadIO m => ResumableSource m o -> m (Source m o, m ())
-- | Provide for a stream of data that can be flushed.
--
-- A number of <tt>Conduit</tt>s (e.g., zlib compression) need the
-- ability to flush the stream at some point. This provides a single
-- wrapper datatype to be used in all such circumstances.
--
-- Since 0.3.0
data Flush a
Chunk :: a -> Flush a
Flush :: Flush a
-- | A wrapper for defining an <a>Applicative</a> instance for <a>Sink</a>s
-- which allows to combine sinks together, generalizing
-- <a>zipSources</a>. A combined sources will take input yielded from
-- each of its <tt>Source</tt>s until any of them stop producing output.
--
-- Since 1.0.13
newtype ZipSource m o
ZipSource :: Source m o -> ZipSource m o
getZipSource :: ZipSource m o -> Source m o
-- | Coalesce all values yielding by all of the <tt>Source</tt>s.
--
-- Implemented on top of <tt>ZipSource</tt>, see that data type for more
-- details.
--
-- Since 1.0.13
sequenceSources :: (Traversable f, Monad m) => f (Source m o) -> Source m (f o)
-- | A wrapper for defining an <a>Applicative</a> instance for <a>Sink</a>s
-- which allows to combine sinks together, generalizing <a>zipSinks</a>.
-- A combined sink distributes the input to all its participants and when
-- all finish, produces the result. This allows to define functions like
--
-- <pre>
-- sequenceSinks :: (Monad m)
-- => [Sink i m r] -> Sink i m [r]
-- sequenceSinks = getZipSink . sequenceA . fmap ZipSink
-- </pre>
--
-- Note that the standard <a>Applicative</a> instance for conduits works
-- differently. It feeds one sink with input until it finishes, then
-- switches to another, etc., and at the end combines their results.
--
-- Since 1.0.13
newtype ZipSink i m r
ZipSink :: Sink i m r -> ZipSink i m r
getZipSink :: ZipSink i m r -> Sink i m r
-- | Send incoming values to all of the <tt>Sink</tt> providing, and
-- ultimately coalesce together all return values.
--
-- Implemented on top of <tt>ZipSink</tt>, see that data type for more
-- details.
--
-- Since 1.0.13
sequenceSinks :: (Traversable f, Monad m) => f (Sink i m r) -> Sink i m (f r)
-- | The Resource transformer. This transformer keeps track of all
-- registered actions, and calls them upon exit (via
-- <a>runResourceT</a>). Actions may be registered via <a>register</a>,
-- or resources may be allocated atomically via <a>allocate</a>.
-- <tt>allocate</tt> corresponds closely to <tt>bracket</tt>.
--
-- Releasing may be performed before exit via the <a>release</a>
-- function. This is a highly recommended optimization, as it will ensure
-- that scarce resources are freed early. Note that calling
-- <tt>release</tt> will deregister the action, so that a release action
-- will only ever be called once.
--
-- Since 0.3.0
data ResourceT (m :: * -> *) a :: (* -> *) -> * -> *
-- | A <tt>Monad</tt> which allows for safe resource allocation. In theory,
-- any monad transformer stack included a <tt>ResourceT</tt> can be an
-- instance of <tt>MonadResource</tt>.
--
-- Note: <tt>runResourceT</tt> has a requirement for a
-- <tt>MonadBaseControl IO m</tt> monad, which allows control operations
-- to be lifted. A <tt>MonadResource</tt> does not have this requirement.
-- This means that transformers such as <tt>ContT</tt> can be an instance
-- of <tt>MonadResource</tt>. However, the <tt>ContT</tt> wrapper will
-- need to be unwrapped before calling <tt>runResourceT</tt>.
--
-- Since 0.3.0
class (MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource (m :: * -> *)
-- | A <tt>Monad</tt> which can throw exceptions. Note that this does not
-- work in a vanilla <tt>ST</tt> or <tt>Identity</tt> monad. Instead, you
-- should use the <a>ExceptionT</a> transformer in your stack if you are
-- dealing with a non-<tt>IO</tt> base monad.
--
-- Since 0.3.0
class Monad m => MonadThrow (m :: * -> *)
monadThrow :: (MonadThrow m, Exception e) => e -> m a
-- | A <tt>Monad</tt> based on some monad which allows running of some
-- <a>IO</a> actions, via unsafe calls. This applies to <a>IO</a> and
-- <a>ST</a>, for instance.
--
-- Since 0.3.0
class Monad m => MonadUnsafeIO (m :: * -> *)
unsafeLiftIO :: MonadUnsafeIO m => IO a -> m a
-- | Unwrap a <a>ResourceT</a> transformer, and call all registered release
-- actions.
--
-- Note that there is some reference counting involved due to
-- <a>resourceForkIO</a>. If multiple threads are sharing the same
-- collection of resources, only the last call to <tt>runResourceT</tt>
-- will deallocate the resources.
--
-- Since 0.3.0
runResourceT :: MonadBaseControl IO m => ResourceT m a -> m a
-- | The express purpose of this transformer is to allow
-- non-<tt>IO</tt>-based monad stacks to catch exceptions via the
-- <a>MonadThrow</a> typeclass.
--
-- Since 0.3.0
newtype ExceptionT (m :: * -> *) a :: (* -> *) -> * -> *
ExceptionT :: m (Either SomeException a) -> ExceptionT a
runExceptionT :: ExceptionT a -> m (Either SomeException a)
-- | Same as <a>runExceptionT</a>, but immediately <a>throw</a> any
-- exception returned.
--
-- Since 0.3.0
runExceptionT_ :: Monad m => ExceptionT m a -> m a
-- | Run an <tt>ExceptionT Identity</tt> stack.
--
-- Since 0.4.2
runException :: ExceptionT Identity a -> Either SomeException a
-- | Run an <tt>ExceptionT Identity</tt> stack, but immediately
-- <a>throw</a> any exception returned.
--
-- Since 0.4.2
runException_ :: ExceptionT Identity a -> a
class MonadBase b m => MonadBaseControl (b :: * -> *) (m :: * -> *) | m -> b
instance Show a => Show (Flush a)
instance Eq a => Eq (Flush a)
instance Ord a => Ord (Flush a)
instance Monad m => Applicative (ZipSink i m)
instance Monad m => Functor (ZipSink i m)
instance Monad m => Applicative (ZipSource m)
instance Monad m => Functor (ZipSource m)
instance Functor Flush
-- | Higher-level functions to interact with the elements of a stream. Most
-- of these are based on list functions.
--
-- Note that these functions all deal with individual elements of a
-- stream as a sort of "black box", where there is no introspection of
-- the contained elements. Values such as <tt>ByteString</tt> and
-- <tt>Text</tt> will likely need to be treated specially to deal with
-- their contents properly (<tt>Word8</tt> and <tt>Char</tt>,
-- respectively). See the <a>Data.Conduit.Binary</a> and
-- <a>Data.Conduit.Text</a> modules.
module Data.Conduit.List
sourceList :: Monad m => [a] -> Producer m a
-- | A source that outputs no values. Note that this is just a
-- type-restricted synonym for <a>mempty</a>.
--
-- Since 0.3.0
sourceNull :: Monad m => Producer m a
-- | Generate a source from a seed value.
--
-- Since 0.4.2
unfold :: Monad m => (b -> Maybe (a, b)) -> b -> Producer m a
-- | Enumerate from a value to a final value, inclusive, via <a>succ</a>.
--
-- This is generally more efficient than using <tt>Prelude</tt>'s
-- <tt>enumFromTo</tt> and combining with <tt>sourceList</tt> since this
-- avoids any intermediate data structures.
--
-- Since 0.4.2
enumFromTo :: (Enum a, Eq a, Monad m) => a -> a -> Producer m a
-- | Produces an infinite stream of repeated applications of f to x.
iterate :: Monad m => (a -> a) -> a -> Producer m a
-- | A strict left fold.
--
-- Since 0.3.0
fold :: Monad m => (b -> a -> b) -> b -> Consumer a m b
-- | A monoidal strict left fold.
--
-- Since 0.5.3
foldMap :: (Monad m, Monoid b) => (a -> b) -> Consumer a m b
-- | Take some values from the stream and return as a list. If you want to
-- instead create a conduit that pipes data to another sink, see
-- <a>isolate</a>. This function is semantically equivalent to:
--
-- <pre>
-- take i = isolate i =$ consume
-- </pre>
--
-- Since 0.3.0
take :: Monad m => Int -> Consumer a m [a]
-- | Ignore a certain number of values in the stream. This function is
-- semantically equivalent to:
--
-- <pre>
-- drop i = take i >> return ()
-- </pre>
--
-- However, <tt>drop</tt> is more efficient as it does not need to hold
-- values in memory.
--
-- Since 0.3.0
drop :: Monad m => Int -> Consumer a m ()
-- | Take a single value from the stream, if available.
--
-- Since 0.3.0
head :: Monad m => Consumer a m (Maybe a)
-- | Look at the next value in the stream, if available. This function will
-- not change the state of the stream.
--
-- Since 0.3.0
peek :: Monad m => Consumer a m (Maybe a)
-- | Consume all values from the stream and return as a list. Note that
-- this will pull all values into memory. For a lazy variant, see
-- <a>Data.Conduit.Lazy</a>.
--
-- Since 0.3.0
consume :: Monad m => Consumer a m [a]
-- | Ignore the remainder of values in the source. Particularly useful when
-- combined with <a>isolate</a>.
--
-- Since 0.3.0
sinkNull :: Monad m => Consumer a m ()
-- | A monoidal strict left fold in a Monad.
--
-- Since 1.0.8
foldMapM :: (Monad m, Monoid b) => (a -> m b) -> Consumer a m b
-- | A monadic strict left fold.
--
-- Since 0.3.0
foldM :: Monad m => (b -> a -> m b) -> b -> Consumer a m b
-- | Apply the action to all values in the stream.
--
-- Since 0.3.0
mapM_ :: Monad m => (a -> m ()) -> Consumer a m ()
-- | Apply a transformation to all values in a stream.
--
-- Since 0.3.0
map :: Monad m => (a -> b) -> Conduit a m b
-- | Apply a transformation that may fail to all values in a stream,
-- discarding the failures.
--
-- Since 0.5.1
mapMaybe :: Monad m => (a -> Maybe b) -> Conduit a m b
-- | Generalization of <a>mapMaybe</a> and <a>concatMap</a>. It applies
-- function to all values in a stream and send values inside resulting
-- <tt>Foldable</tt> downstream.
--
-- Since 1.0.6
mapFoldable :: (Monad m, Foldable f) => (a -> f b) -> Conduit a m b
-- | Filter the <tt>Just</tt> values from a stream, discarding the
-- <tt>Nothing</tt> values.
--
-- Since 0.5.1
catMaybes :: Monad m => Conduit (Maybe a) m a
-- | Generalization of <a>catMaybes</a>. It puts all values from
-- <a>Foldable</a> into stream.
--
-- Since 1.0.6
concat :: (Monad m, Foldable f) => Conduit (f a) m a
-- | Apply a transformation to all values in a stream, concatenating the
-- output values.
--
-- Since 0.3.0
concatMap :: Monad m => (a -> [b]) -> Conduit a m b
-- | <a>concatMap</a> with an accumulator.
--
-- Since 0.3.0
concatMapAccum :: Monad m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b
-- | Analog of <a>scanl</a> for lists.
--
-- Since 1.0.6
scanl :: Monad m => (a -> s -> (s, b)) -> s -> Conduit a m b
-- | Grouping input according to an equality function.
--
-- Since 0.3.0
groupBy :: Monad m => (a -> a -> Bool) -> Conduit a m [a]
-- | Ensure that the inner sink consumes no more than the given number of
-- values. Note this this does <i>not</i> ensure that the sink consumes
-- all of those values. To get the latter behavior, combine with
-- <a>sinkNull</a>, e.g.:
--
-- <pre>
-- src $$ do
-- x <- isolate count =$ do
-- x <- someSink
-- sinkNull
-- return x
-- someOtherSink
-- ...
-- </pre>
--
-- Since 0.3.0
isolate :: Monad m => Int -> Conduit a m a
-- | Keep only values in the stream passing a given predicate.
--
-- Since 0.3.0
filter :: Monad m => (a -> Bool) -> Conduit a m a
-- | Apply a monadic transformation to all values in a stream.
--
-- If you do not need the transformed values, and instead just want the
-- monadic side-effects of running the action, see <a>mapM_</a>.
--
-- Since 0.3.0
mapM :: Monad m => (a -> m b) -> Conduit a m b
-- | Apply a monadic action on all values in a stream.
--
-- This <tt>Conduit</tt> can be used to perform a monadic side-effect for
-- every value, whilst passing the value through the <tt>Conduit</tt>
-- as-is.
--
-- <pre>
-- iterM f = mapM (\a -> f a >>= \() -> return a)
-- </pre>
--
-- Since 0.5.6
iterM :: Monad m => (a -> m ()) -> Conduit a m a
-- | Monadic scanl.
--
-- Since 1.0.6
scanlM :: Monad m => (a -> s -> m (s, b)) -> s -> Conduit a m b
-- | Apply a monadic transformation that may fail to all values in a
-- stream, discarding the failures.
--
-- Since 0.5.1
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Conduit a m b
-- | Monadic variant of <a>mapFoldable</a>.
--
-- Since 1.0.6
mapFoldableM :: (Monad m, Foldable f) => (a -> m (f b)) -> Conduit a m b
-- | Apply a monadic transformation to all values in a stream,
-- concatenating the output values.
--
-- Since 0.3.0
concatMapM :: Monad m => (a -> m [b]) -> Conduit a m b
-- | <a>concatMapM</a> with an accumulator.
--
-- Since 0.3.0
concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b
-- | Run a <tt>Pipe</tt> repeatedly, and output its result value
-- downstream. Stops when no more input is available from upstream.
--
-- Since 0.5.0
sequence :: Monad m => Consumer i m o -> Conduit i m o
-- | Functions for interacting with bytes.
module Data.Conduit.Binary
-- | Stream the contents of a file as binary data.
--
-- Since 0.3.0
sourceFile :: MonadResource m => FilePath -> Producer m ByteString
-- | Stream the contents of a <a>Handle</a> as binary data. Note that this
-- function will <i>not</i> automatically close the <tt>Handle</tt> when
-- processing completes, since it did not acquire the <tt>Handle</tt> in
-- the first place.
--
-- Since 0.3.0
sourceHandle :: MonadIO m => Handle -> Producer m ByteString
-- | Same as <tt>sourceHandle</tt>, but instead of allocating a new buffer
-- for each incoming chunk of data, reuses the same buffer. Therefore,
-- the <tt>ByteString</tt>s yielded by this function are not
-- referentially transparent between two different <tt>yield</tt>s.
--
-- This function will be slightly more efficient than
-- <tt>sourceHandle</tt> by avoiding allocations and reducing garbage
-- collections, but should only be used if you can guarantee that you do
-- not reuse a <tt>ByteString</tt> (or any slice thereof) between two
-- calls to <tt>await</tt>.
--
-- Since 1.0.12
sourceHandleUnsafe :: MonadIO m => Handle -> Source m ByteString
-- | An alternative to <a>sourceHandle</a>. Instead of taking a pre-opened
-- <a>Handle</a>, it takes an action that opens a <a>Handle</a> (in read
-- mode), so that it can open it only when needed and closed it as soon
-- as possible.
--
-- Since 0.3.0
sourceIOHandle :: MonadResource m => IO Handle -> Producer m ByteString
-- | Stream the contents of a file as binary data, starting from a certain
-- offset and only consuming up to a certain number of bytes.
--
-- Since 0.3.0
sourceFileRange :: MonadResource m => FilePath -> Maybe Integer -> Maybe Integer -> Producer m ByteString
-- | Stream the contents of a handle as binary data, starting from a
-- certain offset and only consuming up to a certain number of bytes.
--
-- Since 1.0.8
sourceHandleRange :: MonadIO m => Handle -> Maybe Integer -> Maybe Integer -> Producer m ByteString
-- | Stream all incoming data to the given file.
--
-- Since 0.3.0
sinkFile :: MonadResource m => FilePath -> Consumer ByteString m ()
-- | Stream all incoming data to the given <a>Handle</a>. Note that this
-- function will <i>not</i> automatically close the <tt>Handle</tt> when
-- processing completes.
--
-- Since 0.3.0
sinkHandle :: MonadIO m => Handle -> Consumer ByteString m ()
-- | An alternative to <a>sinkHandle</a>. Instead of taking a pre-opened
-- <a>Handle</a>, it takes an action that opens a <a>Handle</a> (in write
-- mode), so that it can open it only when needed and close it as soon as
-- possible.
--
-- Since 0.3.0
sinkIOHandle :: MonadResource m => IO Handle -> Consumer ByteString m ()
-- | Stream the contents of the input to a file, and also send it along the
-- pipeline. Similar in concept to the Unix command <tt>tee</tt>.
--
-- Since 0.3.0
conduitFile :: MonadResource m => FilePath -> Conduit ByteString m ByteString
-- | Stream the contents of the input to a <tt>Handle</tt>, and also send
-- it along the pipeline. Similar in concept to the Unix command
-- <tt>tee</tt>. Like <tt>sourceHandle</tt>, does not close the handle on
-- completion. Related to: <tt>conduitFile</tt>.
--
-- Since 1.0.9
conduitHandle :: MonadIO m => Handle -> Conduit ByteString m ByteString
-- | Stream the chunks from a lazy bytestring.
--
-- Since 0.5.0
sourceLbs :: Monad m => ByteString -> Producer m ByteString
-- | Return the next byte from the stream, if available.
--
-- Since 0.3.0
head :: Monad m => Consumer ByteString m (Maybe Word8)
-- | Ignore all bytes while the predicate returns <tt>True</tt>.
--
-- Since 0.3.0
dropWhile :: Monad m => (Word8 -> Bool) -> Consumer ByteString m ()
-- | Take the given number of bytes, if available.
--
-- Since 0.3.0
take :: Monad m => Int -> Consumer ByteString m ByteString
-- | Drop up to the given number of bytes.
--
-- Since 0.5.0
drop :: Monad m => Int -> Consumer ByteString m ()
-- | Stream the input data into a temp file and count the number of bytes
-- present. When complete, return a new <tt>Source</tt> reading from the
-- temp file together with the length of the input in bytes.
--
-- All resources will be cleaned up automatically.
--
-- Since 1.0.5
sinkCacheLength :: (MonadResource m1, MonadResource m2) => Sink ByteString m1 (Word64, Source m2 ByteString)
-- | Consume a stream of input into a lazy bytestring. Note that no lazy
-- I/O is performed, but rather all content is read into memory strictly.
--
-- Since 1.0.5
sinkLbs :: Monad m => Sink ByteString m ByteString
-- | Perform a computation on each <tt>Word8</tt> in a stream.
--
-- Since 1.0.10
mapM_ :: Monad m => (Word8 -> m ()) -> Consumer ByteString m ()
-- | Ensure that only up to the given number of bytes are consume by the
-- inner sink. Note that this does <i>not</i> ensure that all of those
-- bytes are in fact consumed.
--
-- Since 0.3.0
isolate :: Monad m => Int -> Conduit ByteString m ByteString
-- | Return all bytes while the predicate returns <tt>True</tt>.
--
-- Since 0.3.0
takeWhile :: Monad m => (Word8 -> Bool) -> Conduit ByteString m ByteString
-- | Split the input bytes into lines. In other words, split on the LF byte
-- (10), and strip it from the output.
--
-- Since 0.3.0
lines :: Monad m => Conduit ByteString m ByteString
-- | Handle streams of text.
--
-- Parts of this code were taken from enumerator and adapted for
-- conduits.
module Data.Conduit.Text
-- | A specific character encoding.
--
-- Since 0.3.0
data Codec
-- | Convert text into bytes, using the provided codec. If the codec is not
-- capable of representing an input character, an exception will be
-- thrown.
--
-- Since 0.3.0
encode :: MonadThrow m => Codec -> Conduit Text m ByteString
-- | Convert bytes into text, using the provided codec. If the codec is not
-- capable of decoding an input byte sequence, an exception will be
-- thrown.
--
-- Since 0.3.0
decode :: MonadThrow m => Codec -> Conduit ByteString m Text
-- | Since 0.3.0
utf8 :: Codec
-- | Since 0.3.0
utf16_le :: Codec
-- | Since 0.3.0
utf16_be :: Codec
-- | Since 0.3.0
utf32_le :: Codec
-- | Since 0.3.0
utf32_be :: Codec
-- | Since 0.3.0
ascii :: Codec
-- | Since 0.3.0
iso8859_1 :: Codec
-- | Emit each line separately
--
-- Since 0.4.1
lines :: Monad m => Conduit Text m Text
-- | Variant of the lines function with an integer parameter. The text
-- length of any emitted line never exceeds the value of the paramater.
-- Whenever this is about to happen a LengthExceeded exception is thrown.
-- This function should be used instead of the lines function whenever we
-- are dealing with user input (e.g. a file upload) because we can't be
-- sure that user input won't have extraordinarily large lines which
-- would require large amounts of memory if consumed.
linesBounded :: MonadThrow m => Int -> Conduit Text m Text
-- | Since 0.3.0
data TextException
DecodeException :: Codec -> Word8 -> TextException
EncodeException :: Codec -> Char -> TextException
LengthExceeded :: Int -> TextException
TextException :: SomeException -> TextException
-- | Since 1.0.8
takeWhile :: Monad m => (Char -> Bool) -> Conduit Text m Text
-- | Since 1.0.8
dropWhile :: Monad m => (Char -> Bool) -> Consumer Text m ()
-- | Since 1.0.8
take :: Monad m => Int -> Conduit Text m Text
-- | Since 1.0.8
drop :: Monad m => Int -> Consumer Text m ()
-- | Since 1.0.8
foldLines :: Monad m => (a -> ConduitM Text o m a) -> a -> ConduitM Text o m a
-- | Since 1.0.8
withLine :: Monad m => Sink Text m a -> Consumer Text m (Maybe a)
instance Typeable TextException
instance Show TextException
instance Exception TextException
instance Show Codec
-- | Use lazy I/O for consuming the contents of a source. Warning: All
-- normal warnings of lazy I/O apply. In particular, if you are using
-- this with a <tt>ResourceT</tt> transformer, you must force the list to
-- be evaluated before exiting the <tt>ResourceT</tt>.
module Data.Conduit.Lazy
-- | Use lazy I/O to consume all elements from a <tt>Source</tt>.
--
-- This function relies on <a>monadActive</a> to determine if the
-- underlying monadic state has been closed.
--
-- Since 0.3.0
lazyConsume :: (MonadBaseControl IO m, MonadActive m) => Source m a -> m [a]
-- | Allow monad transformers to be run<i>eval</i>exec in a section of
-- conduit rather then needing to run across the whole conduit. The
-- circumvents many of the problems with breaking the monad transformer
-- laws. For more information, see the announcement blog post:
-- <a>http://www.yesodweb.com/blog/2014/01/conduit-transformer-exception</a>
--
-- This module was added in conduit 1.0.11.
module Data.Conduit.Lift
-- | Run <a>ErrorT</a> in the base monad
--
-- Since 1.0.11
errorC :: (Monad m, Monad (t (ErrorT e m)), MonadTrans t, Error e, MFunctor t) => t m (Either e b) -> t (ErrorT e m) b
-- | Run <a>ErrorT</a> in the base monad
--
-- Since 1.0.11
runErrorC :: (Monad m, Error e) => ConduitM i o (ErrorT e m) r -> ConduitM i o m (Either e r)
-- | Catch an error in the base monad
--
-- Since 1.0.11
catchErrorC :: (Monad m, Error e) => ConduitM i o (ErrorT e m) r -> (e -> ConduitM i o (ErrorT e m) r) -> ConduitM i o (ErrorT e m) r
-- | Wrap the base monad in <a>MaybeT</a>
--
-- Since 1.0.11
maybeC :: (Monad m, Monad (t (MaybeT m)), MonadTrans t, MFunctor t) => t m (Maybe b) -> t (MaybeT m) b
-- | Run <a>MaybeT</a> in the base monad
--
-- Since 1.0.11
runMaybeC :: Monad m => ConduitM i o (MaybeT m) r -> ConduitM i o m (Maybe r)
-- | Wrap the base monad in <a>ReaderT</a>
--
-- Since 1.0.11
readerC :: (Monad m, Monad (t1 (ReaderT t m)), MonadTrans t1, MFunctor t1) => (t -> t1 m b) -> t1 (ReaderT t m) b
-- | Run <a>ReaderT</a> in the base monad
--
-- Since 1.0.11
runReaderC :: Monad m => r -> ConduitM i o (ReaderT r m) res -> ConduitM i o m res
-- | Wrap the base monad in <a>StateT</a>
--
-- Since 1.0.11
stateC :: (Monad m, Monad (t1 (StateT t m)), MonadTrans t1, MFunctor t1) => (t -> t1 m (b, t)) -> t1 (StateT t m) b
-- | Run <a>StateT</a> in the base monad
--
-- Since 1.0.11
runStateC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m (r, s)
-- | Evaluate <a>StateT</a> in the base monad
--
-- Since 1.0.11
evalStateC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m r
-- | Execute <a>StateT</a> in the base monad
--
-- Since 1.0.11
execStateC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m s
-- | Wrap the base monad in <a>StateT</a>
--
-- Since 1.0.11
stateSC :: (Monad m, Monad (t1 (StateT t m)), MonadTrans t1, MFunctor t1) => (t -> t1 m (b, t)) -> t1 (StateT t m) b
-- | Run <a>StateT</a> in the base monad
--
-- Since 1.0.11
runStateSC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m (r, s)
-- | Evaluate <a>StateT</a> in the base monad
--
-- Since 1.0.11
evalStateSC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m r
-- | Execute <a>StateT</a> in the base monad
--
-- Since 1.0.11
execStateSC :: Monad m => s -> ConduitM i o (StateT s m) r -> ConduitM i o m s
-- | Wrap the base monad in <a>WriterT</a>
--
-- Since 1.0.11
writerC :: (Monad m, Monad (t (WriterT w m)), MonadTrans t, Monoid w, MFunctor t) => t m (b, w) -> t (WriterT w m) b
-- | Run <a>WriterT</a> in the base monad
--
-- Since 1.0.11
runWriterC :: (Monad m, Monoid w) => ConduitM i o (WriterT w m) r -> ConduitM i o m (r, w)
-- | Execute <a>WriterT</a> in the base monad
--
-- Since 1.0.11
execWriterC :: (Monad m, Monoid w) => ConduitM i o (WriterT w m) r -> ConduitM i o m w
-- | Wrap the base monad in <a>WriterT</a>
--
-- Since 1.0.11
writerSC :: (Monad m, Monad (t (WriterT w m)), MonadTrans t, Monoid w, MFunctor t) => t m (b, w) -> t (WriterT w m) b
-- | Run <a>WriterT</a> in the base monad
--
-- Since 1.0.11
runWriterSC :: (Monad m, Monoid w) => ConduitM i o (WriterT w m) r -> ConduitM i o m (r, w)
-- | Execute <a>WriterT</a> in the base monad
--
-- Since 1.0.11
execWriterSC :: (Monad m, Monoid w) => ConduitM i o (WriterT w m) r -> ConduitM i o m w
-- | Wrap the base monad in <a>RWST</a>
--
-- Since 1.0.11
rwsC :: (Monad m, Monad (t1 (RWST t w t2 m)), MonadTrans t1, Monoid w, MFunctor t1) => (t -> t2 -> t1 m (b, t2, w)) -> t1 (RWST t w t2 m) b
-- | Run <a>RWST</a> in the base monad
--
-- Since 1.0.11
runRWSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (res, s, w)
-- | Evaluate <a>RWST</a> in the base monad
--
-- Since 1.0.11
evalRWSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (res, w)
-- | Execute <a>RWST</a> in the base monad
--
-- Since 1.0.11
execRWSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (s, w)
-- | Wrap the base monad in <a>RWST</a>
--
-- Since 1.0.11
rwsSC :: (Monad m, Monad (t1 (RWST t w t2 m)), MonadTrans t1, Monoid w, MFunctor t1) => (t -> t2 -> t1 m (b, t2, w)) -> t1 (RWST t w t2 m) b
-- | Run <a>RWST</a> in the base monad
--
-- Since 1.0.11
runRWSSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (res, s, w)
-- | Evaluate <a>RWST</a> in the base monad
--
-- Since 1.0.11
evalRWSSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (res, w)
-- | Execute <a>RWST</a> in the base monad
--
-- Since 1.0.11
execRWSSC :: (Monad m, Monoid w) => r -> s -> ConduitM i o (RWST r w s m) res -> ConduitM i o m (s, w)
distribute :: (Monad (t (ConduitM b o m)), Monad m, Monad (t m), MonadTrans t, MFunctor t) => ConduitM b o (t m) () -> t (ConduitM b o m) ()
|