/usr/share/doc/libghc-mono-traversable-doc/html/mono-traversable.txt is in libghc-mono-traversable-doc 1.0.6.0-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 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 | -- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Type classes for mapping, folding, and traversing monomorphic containers
--
-- Please see the README at
-- <a>https://www.stackage.org/package/mono-traversable</a>
@package mono-traversable
@version 1.0.6.0
-- | Type classes mirroring standard typeclasses, but working with
-- monomorphic containers.
--
-- The motivation is that some commonly used data types (i.e.,
-- <tt>ByteString</tt> and <tt>Text</tt>) do not allow for instances of
-- typeclasses like <a>Functor</a> and <tt>Foldable</tt>, since they are
-- monomorphic structures. This module allows both monomorphic and
-- polymorphic data types to be instances of the same typeclasses.
--
-- All of the laws for the polymorphic typeclasses apply to their
-- monomorphic cousins. Thus, even though a <a>MonoFunctor</a> instance
-- for <a>Set</a> could theoretically be defined, it is omitted since it
-- could violate the functor law of <tt><a>omap</a> f . <a>omap</a> g =
-- <a>omap</a> (f . g)</tt>.
--
-- Note that all typeclasses have been prefixed with <tt>Mono</tt>, and
-- functions have been prefixed with <tt>o</tt>. The mnemonic for
-- <tt>o</tt> is "only one", or alternatively "it's mono, but m is
-- overused in Haskell, so we'll use the second letter instead." (Agreed,
-- it's not a great mangling scheme, input is welcome!)
module Data.MonoTraversable
-- | Type family for getting the type of the elements of a monomorphic
-- container.
-- | Monomorphic containers that can be mapped over.
class MonoFunctor mono where omap = fmap
-- | Map over a monomorphic container
omap :: MonoFunctor mono => (Element mono -> Element mono) -> mono -> mono
-- | Map over a monomorphic container
omap :: (MonoFunctor mono, Functor f, Element (f a) ~ a, f a ~ mono) => (Element mono -> Element mono) -> mono -> mono
-- | <tt><a>replaceElem</a> old new</tt> replaces all <tt>old</tt> elements
-- with <tt>new</tt>.
replaceElem :: (MonoFunctor mono, Eq (Element mono)) => Element mono -> Element mono -> mono -> mono
replaceElemStrictText :: Char -> Char -> Text -> Text
replaceElemLazyText :: Char -> Char -> Text -> Text
-- | Monomorphic containers that can be folded.
class MonoFoldable mono where ofoldMap = foldMap ofoldr = foldr ofoldl' = foldl' otoList t = build (\ mono n -> ofoldr mono n t) oall f = getAll . ofoldMap (All . f) oany f = getAny . ofoldMap (Any . f) onull = oall (const False) olength = ofoldl' (\ i _ -> i + 1) 0 olength64 = ofoldl' (\ i _ -> i + 1) 0 ocompareLength c0 i0 = olength c0 `compare` fromIntegral i0 otraverse_ f = ofoldr ((*>) . f) (pure ()) ofor_ = flip otraverse_ omapM_ = otraverse_ oforM_ = flip omapM_ ofoldlM f z0 xs = ofoldr f' return xs z0 where f' x k z = f z x >>= k ofoldMap1Ex f = fromMaybe (error "Data.MonoTraversable.ofoldMap1Ex") . getOption . ofoldMap (Option . Just . f) ofoldr1Ex = foldr1 ofoldl1Ex' = foldl1 headEx = ofoldr const (error "Data.MonoTraversable.headEx: empty") lastEx = ofoldl1Ex' (flip const) unsafeHead = headEx unsafeLast = lastEx maximumByEx f = ofoldl1Ex' go where go x y = case f x y of { LT -> y _ -> x } minimumByEx f = ofoldl1Ex' go where go x y = case f x y of { GT -> y _ -> x } oelem e = elem e . otoList onotElem e = notElem e . otoList
-- | Map each element of a monomorphic container to a <a>Monoid</a> and
-- combine the results.
ofoldMap :: (MonoFoldable mono, Monoid m) => (Element mono -> m) -> mono -> m
-- | Map each element of a monomorphic container to a <a>Monoid</a> and
-- combine the results.
ofoldMap :: (MonoFoldable mono, t a ~ mono, a ~ Element (t a), Foldable t, Monoid m) => (Element mono -> m) -> mono -> m
-- | Right-associative fold of a monomorphic container.
ofoldr :: MonoFoldable mono => (Element mono -> b -> b) -> b -> mono -> b
-- | Right-associative fold of a monomorphic container.
ofoldr :: (MonoFoldable mono, t a ~ mono, a ~ Element (t a), Foldable t) => (Element mono -> b -> b) -> b -> mono -> b
-- | Strict left-associative fold of a monomorphic container.
ofoldl' :: MonoFoldable mono => (a -> Element mono -> a) -> a -> mono -> a
-- | Strict left-associative fold of a monomorphic container.
ofoldl' :: (MonoFoldable mono, t b ~ mono, b ~ Element (t b), Foldable t) => (a -> Element mono -> a) -> a -> mono -> a
-- | Convert a monomorphic container to a list.
otoList :: MonoFoldable mono => mono -> [Element mono]
-- | Are <b>all</b> of the elements in a monomorphic container converted to
-- booleans <a>True</a>?
oall :: MonoFoldable mono => (Element mono -> Bool) -> mono -> Bool
-- | Are <b>any</b> of the elements in a monomorphic container converted to
-- booleans <a>True</a>?
oany :: MonoFoldable mono => (Element mono -> Bool) -> mono -> Bool
-- | Is the monomorphic container empty?
onull :: MonoFoldable mono => mono -> Bool
-- | Length of a monomorphic container, returns a <a>Int</a>.
olength :: MonoFoldable mono => mono -> Int
-- | Length of a monomorphic container, returns a <a>Int64</a>.
olength64 :: MonoFoldable mono => mono -> Int64
-- | Compare the length of a monomorphic container and a given number.
ocompareLength :: (MonoFoldable mono, Integral i) => mono -> i -> Ordering
-- | Map each element of a monomorphic container to an action, evaluate
-- these actions from left to right, and ignore the results.
otraverse_ :: (MonoFoldable mono, Applicative f) => (Element mono -> f b) -> mono -> f ()
-- | <a>ofor_</a> is <a>otraverse_</a> with its arguments flipped.
ofor_ :: (MonoFoldable mono, Applicative f) => mono -> (Element mono -> f b) -> f ()
-- | Map each element of a monomorphic container to a monadic action,
-- evaluate these actions from left to right, and ignore the results.
omapM_ :: (MonoFoldable mono, Applicative m) => (Element mono -> m ()) -> mono -> m ()
-- | <a>oforM_</a> is <a>omapM_</a> with its arguments flipped.
oforM_ :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m ()
-- | Monadic fold over the elements of a monomorphic container, associating
-- to the left.
ofoldlM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a
-- | Map each element of a monomorphic container to a semigroup, and
-- combine the results.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>ofoldMap1</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
ofoldMap1Ex :: (MonoFoldable mono, Semigroup m) => (Element mono -> m) -> mono -> m
-- | Right-associative fold of a monomorphic container with no base
-- element.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>ofoldr1Ex</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
ofoldr1Ex :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Right-associative fold of a monomorphic container with no base
-- element.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>ofoldr1Ex</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
ofoldr1Ex :: (MonoFoldable mono, t a ~ mono, a ~ Element (t a), Foldable t) => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Strict left-associative fold of a monomorphic container with no base
-- element.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>ofoldl1Ex'</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
ofoldl1Ex' :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Strict left-associative fold of a monomorphic container with no base
-- element.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>ofoldl1Ex'</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
ofoldl1Ex' :: (MonoFoldable mono, t a ~ mono, a ~ Element (t a), Foldable t) => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Get the first element of a monomorphic container.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>head</a> from <a>Data.NonNull</a> for a total version of
-- this function.</i>
headEx :: MonoFoldable mono => mono -> Element mono
-- | Get the last element of a monomorphic container.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See 'Data.NonNull.last from <a>Data.NonNull</a> for a total version
-- of this function.</i>
lastEx :: MonoFoldable mono => mono -> Element mono
-- | Equivalent to <a>headEx</a>.
unsafeHead :: MonoFoldable mono => mono -> Element mono
-- | Equivalent to <a>lastEx</a>.
unsafeLast :: MonoFoldable mono => mono -> Element mono
-- | Get the maximum element of a monomorphic container, using a supplied
-- element ordering function.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>maximiumBy</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
maximumByEx :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Element mono
-- | Get the minimum element of a monomorphic container, using a supplied
-- element ordering function.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>minimumBy</a> from <a>Data.NonNull</a> for a total version
-- of this function.</i>
minimumByEx :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Element mono
-- | Checks if the monomorphic container includes the supplied element.
oelem :: (MonoFoldable mono, Eq (Element mono)) => Element mono -> mono -> Bool
-- | Checks if the monomorphic container does not include the supplied
-- element.
onotElem :: (MonoFoldable mono, Eq (Element mono)) => Element mono -> mono -> Bool
-- | Safe version of <a>headEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
headMay :: MonoFoldable mono => mono -> Maybe (Element mono)
-- | Safe version of <a>lastEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
lastMay :: MonoFoldable mono => mono -> Maybe (Element mono)
-- | <a>osum</a> computes the sum of the numbers of a monomorphic
-- container.
osum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
-- | <a>oproduct</a> computes the product of the numbers of a monomorphic
-- container.
oproduct :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
-- | Are <b>all</b> of the elements <a>True</a>?
--
-- Since 0.6.0
oand :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool
-- | Are <b>any</b> of the elements <a>True</a>?
--
-- Since 0.6.0
oor :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool
-- | Synonym for <a>ofoldMap</a>
oconcatMap :: (MonoFoldable mono, Monoid m) => (Element mono -> m) -> mono -> m
-- | Monoidally combine all values in the container
ofold :: (MonoFoldable mono, Monoid (Element mono)) => mono -> Element mono
-- | Synonym for <a>ofold</a>
oconcat :: (MonoFoldable mono, Monoid (Element mono)) => mono -> Element mono
-- | Synonym for <a>ofoldlM</a>
ofoldM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a
-- | Perform all actions in the given container
osequence_ :: (Applicative m, MonoFoldable mono, Element mono ~ (m ())) => mono -> m ()
-- | Get the minimum element of a monomorphic container.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>maximum</a> from <a>Data.NonNull</a> for a total version of
-- this function.</i>
maximumEx :: (MonoFoldable mono, Ord (Element mono)) => mono -> Element mono
-- | Get the maximum element of a monomorphic container.
--
-- Note: this is a partial function. On an empty <a>MonoFoldable</a>, it
-- will throw an exception.
--
-- <i>See <a>minimum</a> from <a>Data.NonNull</a> for a total version of
-- this function.</i>
minimumEx :: (MonoFoldable mono, Ord (Element mono)) => mono -> Element mono
-- | Safe version of <a>maximumEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
maximumMay :: (MonoFoldable mono, Ord (Element mono)) => mono -> Maybe (Element mono)
-- | Safe version of <a>maximumByEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
maximumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono)
-- | Safe version of <a>minimumEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
minimumMay :: (MonoFoldable mono, Ord (Element mono)) => mono -> Maybe (Element mono)
-- | Safe version of <a>minimumByEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
minimumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono)
-- | Monomorphic containers that can be traversed from left to right.
class (MonoFunctor mono, MonoFoldable mono) => MonoTraversable mono where otraverse = traverse omapM = otraverse
-- | Map each element of a monomorphic container to an action, evaluate
-- these actions from left to right, and collect the results.
otraverse :: (MonoTraversable mono, Applicative f) => (Element mono -> f (Element mono)) -> mono -> f mono
-- | Map each element of a monomorphic container to an action, evaluate
-- these actions from left to right, and collect the results.
otraverse :: (MonoTraversable mono, Traversable t, mono ~ t a, a ~ Element mono, Applicative f) => (Element mono -> f (Element mono)) -> mono -> f mono
-- | Map each element of a monomorphic container to a monadic action,
-- evaluate these actions from left to right, and collect the results.
omapM :: (MonoTraversable mono, Applicative m) => (Element mono -> m (Element mono)) -> mono -> m mono
-- | <a>ofor</a> is <a>otraverse</a> with its arguments flipped.
ofor :: (MonoTraversable mono, Applicative f) => mono -> (Element mono -> f (Element mono)) -> f mono
-- | <a>oforM</a> is <a>omapM</a> with its arguments flipped.
oforM :: (MonoTraversable mono, Applicative f) => mono -> (Element mono -> f (Element mono)) -> f mono
-- | A strict left fold, together with an unwrap function.
--
-- This is convenient when the accumulator value is not the same as the
-- final expected type. It is provided mainly for integration with the
-- <tt>foldl</tt> package, to be used in conjunction with
-- <tt>purely</tt>.
--
-- Since 0.3.1
ofoldlUnwrap :: MonoFoldable mono => (x -> Element mono -> x) -> x -> (x -> b) -> mono -> b
-- | A monadic strict left fold, together with an unwrap function.
--
-- Similar to <tt>foldlUnwrap</tt>, but allows monadic actions. To be
-- used with <tt>impurely</tt> from <tt>foldl</tt>.
--
-- Since 0.3.1
ofoldMUnwrap :: (Monad m, MonoFoldable mono) => (x -> Element mono -> m x) -> m x -> (x -> m b) -> mono -> m b
-- | Typeclass for monomorphic containers that an element can be lifted
-- into.
--
-- For any <a>MonoFunctor</a>, the following law holds:
--
-- <pre>
-- <a>omap</a> f . <a>opoint</a> = <a>opoint</a> . f
-- </pre>
class MonoPointed mono where opoint = pure
-- | Lift an element into a monomorphic container.
--
-- <a>opoint</a> is the same as <a>pure</a> for an <a>Applicative</a>
opoint :: MonoPointed mono => Element mono -> mono
-- | Lift an element into a monomorphic container.
--
-- <a>opoint</a> is the same as <a>pure</a> for an <a>Applicative</a>
opoint :: (MonoPointed mono, Applicative f, (f a) ~ mono, Element (f a) ~ a) => Element mono -> mono
-- | Typeclass for monomorphic containers where it is always okay to
-- "extract" a value from with <a>oextract</a>, and where you can
-- extrapolate any "extracting" function to be a function on the whole
-- part with <a>oextend</a>.
--
-- <a>oextend</a> and <a>oextract</a> should work together following the
-- laws:
--
-- <pre>
-- <a>oextend</a> <a>oextract</a> = <a>id</a>
-- <a>oextract</a> . <a>oextend</a> f = f
-- <a>oextend</a> f . <a>oextend</a> g = <a>oextend</a> (f . <a>oextend</a> g)
-- </pre>
--
-- As an intuition, <tt><a>oextend</a> f</tt> uses <tt>f</tt> to "build
-- up" a new <tt>mono</tt> with pieces from the old one received by
-- <tt>f</tt>.
class MonoFunctor mono => MonoComonad mono
-- | Extract an element from <tt>mono</tt>. Can be thought of as a dual
-- concept to <tt>opoint</tt>.
oextract :: MonoComonad mono => mono -> Element mono
-- | <a>Extend</a> a <tt>mono -> <a>Element</a> mono</tt> function to be
-- a <tt>mono -> mono</tt>; that is, builds a new <tt>mono</tt> from
-- the old one by using pieces glimpsed from the given function.
oextend :: MonoComonad mono => (mono -> Element mono) -> mono -> mono
-- | Containers which, when two values are combined, the combined length is
-- no less than the larger of the two inputs. In code:
--
-- <pre>
-- olength (x <> y) >= max (olength x) (olength y)
-- </pre>
--
-- This class has no methods, and is simply used to assert that this law
-- holds, in order to provide guarantees of correctness (see, for
-- instance, <a>Data.NonNull</a>).
--
-- This should have a <tt>Semigroup</tt> superclass constraint, however,
-- due to <tt>Semigroup</tt> only recently moving to base, some packages
-- do not provide instances.
class MonoFoldable mono => GrowingAppend mono
-- | <tt>intercalate</tt> <tt>seq seqs</tt> inserts <tt>seq</tt> in between
-- <tt>seqs</tt> and concatenates the result.
ointercalate :: (MonoFoldable mono, Monoid (Element mono)) => Element mono -> mono -> Element mono
instance Data.MonoTraversable.MonoFunctor Data.ByteString.Internal.ByteString
instance Data.MonoTraversable.MonoFunctor Data.ByteString.Lazy.Internal.ByteString
instance Data.MonoTraversable.MonoFunctor Data.Text.Internal.Text
instance Data.MonoTraversable.MonoFunctor Data.Text.Internal.Lazy.Text
instance Data.MonoTraversable.MonoFunctor [a]
instance Data.MonoTraversable.MonoFunctor (GHC.Types.IO a)
instance Data.MonoTraversable.MonoFunctor (Control.Applicative.ZipList a)
instance Data.MonoTraversable.MonoFunctor (GHC.Base.Maybe a)
instance Data.MonoTraversable.MonoFunctor (Data.Tree.Tree a)
instance Data.MonoTraversable.MonoFunctor (Data.Sequence.Seq a)
instance Data.MonoTraversable.MonoFunctor (Data.Sequence.ViewL a)
instance Data.MonoTraversable.MonoFunctor (Data.Sequence.ViewR a)
instance Data.MonoTraversable.MonoFunctor (Data.IntMap.Base.IntMap a)
instance Data.MonoTraversable.MonoFunctor (Data.Semigroup.Option a)
instance Data.MonoTraversable.MonoFunctor (Data.List.NonEmpty.NonEmpty a)
instance Data.MonoTraversable.MonoFunctor (Data.Functor.Identity.Identity a)
instance Data.MonoTraversable.MonoFunctor (r -> a)
instance Data.MonoTraversable.MonoFunctor (Data.Either.Either a b)
instance Data.MonoTraversable.MonoFunctor (a, b)
instance Data.MonoTraversable.MonoFunctor (Data.Functor.Const.Const m a)
instance GHC.Base.Monad m => Data.MonoTraversable.MonoFunctor (Control.Applicative.WrappedMonad m a)
instance Data.MonoTraversable.MonoFunctor (Data.Map.Base.Map k v)
instance Data.MonoTraversable.MonoFunctor (Data.HashMap.Base.HashMap k v)
instance Data.MonoTraversable.MonoFunctor (Data.Vector.Vector a)
instance Data.MonoTraversable.MonoFunctor (Data.Semigroup.Arg a b)
instance Control.Arrow.Arrow a => Data.MonoTraversable.MonoFunctor (Control.Applicative.WrappedArrow a b c)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Maybe.MaybeT m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.List.ListT m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Identity.IdentityT m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Writer.Lazy.WriterT w m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Writer.Strict.WriterT w m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.State.Lazy.StateT s m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.State.Strict.StateT s m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.RWS.Lazy.RWST r w s m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.RWS.Strict.RWST r w s m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Reader.ReaderT r m a)
instance GHC.Base.Functor m => Data.MonoTraversable.MonoFunctor (Control.Monad.Trans.Cont.ContT r m a)
instance (GHC.Base.Functor f, GHC.Base.Functor g) => Data.MonoTraversable.MonoFunctor (Data.Functor.Compose.Compose f g a)
instance (GHC.Base.Functor f, GHC.Base.Functor g) => Data.MonoTraversable.MonoFunctor (Data.Functor.Product.Product f g a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.MonoTraversable.MonoFunctor (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.MonoTraversable.MonoFunctor (Data.Vector.Storable.Vector a)
instance Data.MonoTraversable.MonoFoldable Data.ByteString.Internal.ByteString
instance Data.MonoTraversable.MonoFoldable Data.ByteString.Lazy.Internal.ByteString
instance Data.MonoTraversable.MonoFoldable Data.Text.Internal.Text
instance Data.MonoTraversable.MonoFoldable Data.Text.Internal.Lazy.Text
instance Data.MonoTraversable.MonoFoldable Data.IntSet.Base.IntSet
instance Data.MonoTraversable.MonoFoldable [a]
instance Data.MonoTraversable.MonoFoldable (GHC.Base.Maybe a)
instance Data.MonoTraversable.MonoFoldable (Data.Tree.Tree a)
instance Data.MonoTraversable.MonoFoldable (Data.Sequence.Seq a)
instance Data.MonoTraversable.MonoFoldable (Data.Sequence.ViewL a)
instance Data.MonoTraversable.MonoFoldable (Data.Sequence.ViewR a)
instance Data.MonoTraversable.MonoFoldable (Data.IntMap.Base.IntMap a)
instance Data.MonoTraversable.MonoFoldable (Data.Semigroup.Option a)
instance Data.MonoTraversable.MonoFoldable (Data.List.NonEmpty.NonEmpty a)
instance Data.MonoTraversable.MonoFoldable (Data.Functor.Identity.Identity a)
instance Data.MonoTraversable.MonoFoldable (Data.Map.Base.Map k v)
instance Data.MonoTraversable.MonoFoldable (Data.HashMap.Base.HashMap k v)
instance Data.MonoTraversable.MonoFoldable (Data.Vector.Vector a)
instance GHC.Classes.Ord e => Data.MonoTraversable.MonoFoldable (Data.Set.Base.Set e)
instance Data.MonoTraversable.MonoFoldable (Data.HashSet.HashSet e)
instance Data.Vector.Unboxed.Base.Unbox a => Data.MonoTraversable.MonoFoldable (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.MonoTraversable.MonoFoldable (Data.Vector.Storable.Vector a)
instance Data.MonoTraversable.MonoFoldable (Data.Either.Either a b)
instance Data.MonoTraversable.MonoFoldable (a, b)
instance Data.MonoTraversable.MonoFoldable (Data.Functor.Const.Const m a)
instance Data.Foldable.Foldable f => Data.MonoTraversable.MonoFoldable (Control.Monad.Trans.Maybe.MaybeT f a)
instance Data.Foldable.Foldable f => Data.MonoTraversable.MonoFoldable (Control.Monad.Trans.List.ListT f a)
instance Data.Foldable.Foldable f => Data.MonoTraversable.MonoFoldable (Control.Monad.Trans.Identity.IdentityT f a)
instance Data.Foldable.Foldable f => Data.MonoTraversable.MonoFoldable (Control.Monad.Trans.Writer.Lazy.WriterT w f a)
instance Data.Foldable.Foldable f => Data.MonoTraversable.MonoFoldable (Control.Monad.Trans.Writer.Strict.WriterT w f a)
instance (Data.Foldable.Foldable f, Data.Foldable.Foldable g) => Data.MonoTraversable.MonoFoldable (Data.Functor.Compose.Compose f g a)
instance (Data.Foldable.Foldable f, Data.Foldable.Foldable g) => Data.MonoTraversable.MonoFoldable (Data.Functor.Product.Product f g a)
instance Data.MonoTraversable.MonoTraversable Data.ByteString.Internal.ByteString
instance Data.MonoTraversable.MonoTraversable Data.ByteString.Lazy.Internal.ByteString
instance Data.MonoTraversable.MonoTraversable Data.Text.Internal.Text
instance Data.MonoTraversable.MonoTraversable Data.Text.Internal.Lazy.Text
instance Data.MonoTraversable.MonoTraversable [a]
instance Data.MonoTraversable.MonoTraversable (GHC.Base.Maybe a)
instance Data.MonoTraversable.MonoTraversable (Data.Tree.Tree a)
instance Data.MonoTraversable.MonoTraversable (Data.Sequence.Seq a)
instance Data.MonoTraversable.MonoTraversable (Data.Sequence.ViewL a)
instance Data.MonoTraversable.MonoTraversable (Data.Sequence.ViewR a)
instance Data.MonoTraversable.MonoTraversable (Data.IntMap.Base.IntMap a)
instance Data.MonoTraversable.MonoTraversable (Data.Semigroup.Option a)
instance Data.MonoTraversable.MonoTraversable (Data.List.NonEmpty.NonEmpty a)
instance Data.MonoTraversable.MonoTraversable (Data.Functor.Identity.Identity a)
instance Data.MonoTraversable.MonoTraversable (Data.Map.Base.Map k v)
instance Data.MonoTraversable.MonoTraversable (Data.HashMap.Base.HashMap k v)
instance Data.MonoTraversable.MonoTraversable (Data.Vector.Vector a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.MonoTraversable.MonoTraversable (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.MonoTraversable.MonoTraversable (Data.Vector.Storable.Vector a)
instance Data.MonoTraversable.MonoTraversable (Data.Either.Either a b)
instance Data.MonoTraversable.MonoTraversable (a, b)
instance Data.MonoTraversable.MonoTraversable (Data.Functor.Const.Const m a)
instance Data.Traversable.Traversable f => Data.MonoTraversable.MonoTraversable (Control.Monad.Trans.Maybe.MaybeT f a)
instance Data.Traversable.Traversable f => Data.MonoTraversable.MonoTraversable (Control.Monad.Trans.List.ListT f a)
instance Data.Traversable.Traversable f => Data.MonoTraversable.MonoTraversable (Control.Monad.Trans.Identity.IdentityT f a)
instance Data.Traversable.Traversable f => Data.MonoTraversable.MonoTraversable (Control.Monad.Trans.Writer.Lazy.WriterT w f a)
instance Data.Traversable.Traversable f => Data.MonoTraversable.MonoTraversable (Control.Monad.Trans.Writer.Strict.WriterT w f a)
instance (Data.Traversable.Traversable f, Data.Traversable.Traversable g) => Data.MonoTraversable.MonoTraversable (Data.Functor.Compose.Compose f g a)
instance (Data.Traversable.Traversable f, Data.Traversable.Traversable g) => Data.MonoTraversable.MonoTraversable (Data.Functor.Product.Product f g a)
instance Data.MonoTraversable.MonoPointed Data.ByteString.Internal.ByteString
instance Data.MonoTraversable.MonoPointed Data.ByteString.Lazy.Internal.ByteString
instance Data.MonoTraversable.MonoPointed Data.Text.Internal.Text
instance Data.MonoTraversable.MonoPointed Data.Text.Internal.Lazy.Text
instance Data.MonoTraversable.MonoPointed [a]
instance Data.MonoTraversable.MonoPointed (GHC.Base.Maybe a)
instance Data.MonoTraversable.MonoPointed (Data.Semigroup.Option a)
instance Data.MonoTraversable.MonoPointed (Data.List.NonEmpty.NonEmpty a)
instance Data.MonoTraversable.MonoPointed (Data.Functor.Identity.Identity a)
instance Data.MonoTraversable.MonoPointed (Data.Vector.Vector a)
instance Data.MonoTraversable.MonoPointed (GHC.Types.IO a)
instance Data.MonoTraversable.MonoPointed (Control.Applicative.ZipList a)
instance Data.MonoTraversable.MonoPointed (r -> a)
instance GHC.Base.Monoid a => Data.MonoTraversable.MonoPointed (a, b)
instance GHC.Base.Monoid m => Data.MonoTraversable.MonoPointed (Data.Functor.Const.Const m a)
instance GHC.Base.Monad m => Data.MonoTraversable.MonoPointed (Control.Applicative.WrappedMonad m a)
instance GHC.Base.Applicative m => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.List.ListT m a)
instance GHC.Base.Applicative m => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Identity.IdentityT m a)
instance Control.Arrow.Arrow a => Data.MonoTraversable.MonoPointed (Control.Applicative.WrappedArrow a b c)
instance (GHC.Base.Monoid w, GHC.Base.Applicative m) => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Writer.Lazy.WriterT w m a)
instance (GHC.Base.Monoid w, GHC.Base.Applicative m) => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Writer.Strict.WriterT w m a)
instance GHC.Base.Applicative m => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Reader.ReaderT r m a)
instance Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Cont.ContT r m a)
instance (GHC.Base.Applicative f, GHC.Base.Applicative g) => Data.MonoTraversable.MonoPointed (Data.Functor.Compose.Compose f g a)
instance (GHC.Base.Applicative f, GHC.Base.Applicative g) => Data.MonoTraversable.MonoPointed (Data.Functor.Product.Product f g a)
instance Data.MonoTraversable.MonoPointed (Data.Sequence.Seq a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.MonoTraversable.MonoPointed (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.MonoTraversable.MonoPointed (Data.Vector.Storable.Vector a)
instance Data.MonoTraversable.MonoPointed (Data.Either.Either a b)
instance Data.MonoTraversable.MonoPointed Data.IntSet.Base.IntSet
instance Data.MonoTraversable.MonoPointed (Data.Set.Base.Set a)
instance Data.Hashable.Class.Hashable a => Data.MonoTraversable.MonoPointed (Data.HashSet.HashSet a)
instance GHC.Base.Applicative f => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.Maybe.MaybeT f a)
instance (GHC.Base.Monoid w, GHC.Base.Applicative m) => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.RWS.Lazy.RWST r w s m a)
instance (GHC.Base.Monoid w, GHC.Base.Applicative m) => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.RWS.Strict.RWST r w s m a)
instance GHC.Base.Applicative m => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.State.Lazy.StateT s m a)
instance GHC.Base.Applicative m => Data.MonoTraversable.MonoPointed (Control.Monad.Trans.State.Strict.StateT s m a)
instance Data.MonoTraversable.MonoPointed (Data.Sequence.ViewL a)
instance Data.MonoTraversable.MonoPointed (Data.Sequence.ViewR a)
instance Data.MonoTraversable.MonoPointed (Data.Tree.Tree a)
instance Data.MonoTraversable.MonoComonad (Data.Sequence.ViewL a)
instance Data.MonoTraversable.MonoComonad (Data.Sequence.ViewR a)
instance Data.MonoTraversable.GrowingAppend (Data.Sequence.Seq a)
instance Data.MonoTraversable.GrowingAppend [a]
instance Data.MonoTraversable.GrowingAppend (Data.Vector.Vector a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.MonoTraversable.GrowingAppend (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.MonoTraversable.GrowingAppend (Data.Vector.Storable.Vector a)
instance Data.MonoTraversable.GrowingAppend Data.ByteString.Internal.ByteString
instance Data.MonoTraversable.GrowingAppend Data.ByteString.Lazy.Internal.ByteString
instance Data.MonoTraversable.GrowingAppend Data.Text.Internal.Text
instance Data.MonoTraversable.GrowingAppend Data.Text.Internal.Lazy.Text
instance Data.MonoTraversable.GrowingAppend (Data.List.NonEmpty.NonEmpty a)
instance GHC.Classes.Ord k => Data.MonoTraversable.GrowingAppend (Data.Map.Base.Map k v)
instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.MonoTraversable.GrowingAppend (Data.HashMap.Base.HashMap k v)
instance GHC.Classes.Ord v => Data.MonoTraversable.GrowingAppend (Data.Set.Base.Set v)
instance (GHC.Classes.Eq v, Data.Hashable.Class.Hashable v) => Data.MonoTraversable.GrowingAppend (Data.HashSet.HashSet v)
instance Data.MonoTraversable.GrowingAppend Data.IntSet.Base.IntSet
instance Data.MonoTraversable.GrowingAppend (Data.IntMap.Base.IntMap v)
-- | The functions in <a>Data.MonoTraversable</a> are all prefixed with the
-- letter <tt>o</tt> to avoid conflicts with their polymorphic
-- counterparts. This module exports the same identifiers without the
-- prefix, for all cases where the monomorphic variant loses no
-- generality versus the polymorphic version. For example, <a>olength</a>
-- is just as general as <tt>Data.Foldable.length</tt>, so we export
-- <tt>length = length</tt>. By contrast, <a>omap</a> cannot fully
-- subsume <tt>fmap</tt> or <tt>map</tt>, so we do not provide such an
-- export.
module Data.MonoTraversable.Unprefixed
-- | Synonym for <a>ofoldMap</a>
foldMap :: (MonoFoldable mono, Monoid m) => (Element mono -> m) -> mono -> m
-- | Synonym for <a>ofoldr</a>
foldr :: MonoFoldable mono => (Element mono -> b -> b) -> b -> mono -> b
-- | Synonym for <a>ofoldl'</a>
foldl' :: MonoFoldable mono => (a -> Element mono -> a) -> a -> mono -> a
-- | Synonym for <a>otoList</a>
toList :: MonoFoldable mono => mono -> [Element mono]
-- | Synonym for <a>oall</a>
all :: MonoFoldable mono => (Element mono -> Bool) -> mono -> Bool
-- | Synonym for <a>oany</a>
any :: MonoFoldable mono => (Element mono -> Bool) -> mono -> Bool
-- | Synonym for <a>onull</a>
null :: MonoFoldable mono => mono -> Bool
-- | Synonym for <a>olength</a>
length :: MonoFoldable mono => mono -> Int
-- | Synonym for <a>olength64</a>
length64 :: MonoFoldable mono => mono -> Int64
-- | Synonym for <a>ocompareLength</a>
compareLength :: (MonoFoldable mono, Integral i) => mono -> i -> Ordering
-- | Synonym for <a>otraverse_</a>
traverse_ :: (MonoFoldable mono, Applicative f) => (Element mono -> f b) -> mono -> f ()
-- | Synonym for <a>ofor_</a>
for_ :: (MonoFoldable mono, Applicative f) => mono -> (Element mono -> f b) -> f ()
-- | Synonym for <a>omapM_</a>
mapM_ :: (MonoFoldable mono, Applicative m) => (Element mono -> m ()) -> mono -> m ()
-- | Synonym for <a>oforM_</a>
forM_ :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m ()
-- | Synonym for <a>ofoldlM</a>
foldlM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a
-- | Synonym for <a>ofoldMap1Ex</a>
foldMap1Ex :: (MonoFoldable mono, Semigroup m) => (Element mono -> m) -> mono -> m
-- | Synonym for <a>ofoldr1Ex</a>
foldr1Ex :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Synonym for <a>ofoldl1Ex'</a>
foldl1Ex' :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> mono -> Element mono
-- | Synonym for <a>osum</a>
sum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
-- | Synonym for <a>oproduct</a>
product :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
-- | Synonym for <a>oand</a>
and :: (MonoFoldable mono, Element mono ~ Bool) => mono -> Bool
-- | Synonym for <a>oor</a>
or :: (MonoFoldable mono, Element mono ~ Bool) => mono -> Bool
-- | Synonym for <a>oconcatMap</a>
concatMap :: (MonoFoldable mono, Monoid m) => (Element mono -> m) -> mono -> m
-- | Synonym for <a>oelem</a>
elem :: (MonoFoldable mono, Eq (Element mono)) => Element mono -> mono -> Bool
-- | Synonym for <a>onotElem</a>
notElem :: (MonoFoldable mono, Eq (Element mono)) => Element mono -> mono -> Bool
-- | Synonym for <a>opoint</a>
point :: MonoPointed mono => Element mono -> mono
-- | Synonym for <a>ointercalate</a>
intercalate :: (MonoFoldable mono, Monoid (Element mono)) => Element mono -> mono -> Element mono
-- | Synonym for <a>ofold</a>
fold :: (MonoFoldable mono, Monoid (Element mono)) => mono -> Element mono
-- | Synonym for <a>oconcat</a>
concat :: (MonoFoldable mono, Monoid (Element mono)) => mono -> Element mono
-- | Synonym for <a>ofoldM</a>
foldM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a
-- | Synonym for <a>osequence_</a>
sequence_ :: (Applicative m, MonoFoldable mono, Element mono ~ (m ())) => mono -> m ()
-- | Abstractions over sequential data structures, like lists and vectors.
module Data.Sequences
-- | <a>SemiSequence</a> was created to share code between
-- <a>IsSequence</a> and <tt>NonNull</tt>.
--
-- <tt>Semi</tt> means <tt>SemiGroup</tt> A <a>SemiSequence</a> can
-- accomodate a <tt>SemiGroup</tt> such as <tt>NonEmpty</tt> or
-- <tt>NonNull</tt> A Monoid should be able to fill out
-- <a>IsSequence</a>.
--
-- <a>SemiSequence</a> operations maintain the same type because they all
-- maintain the same number of elements or increase them. However, a
-- decreasing function such as filter may change they type. For example,
-- from <tt>NonEmpty</tt> to '[]' This type-changing function exists on
-- <tt>NonNull</tt> as <tt>nfilter</tt>
--
-- <a>filter</a> and other such functions are placed in <a>IsSequence</a>
--
-- <i>NOTE</i>: Like <a>GrowingAppend</a>, ideally we'd have a
-- <tt>Semigroup</tt> superclass constraint here, but that would pull in
-- more dependencies to this package than desired.
class (Integral (Index seq), GrowingAppend seq) => SemiSequence seq where type Index seq where {
type family Index seq;
}
-- | <a>intersperse</a> takes an element and intersperses that element
-- between the elements of the sequence.
--
-- <pre>
-- > <a>intersperse</a> ',' "abcde"
-- "a,b,c,d,e"
-- </pre>
intersperse :: SemiSequence seq => Element seq -> seq -> seq
-- | Reverse a sequence
--
-- <pre>
-- > <a>reverse</a> "hello world"
-- "dlrow olleh"
-- </pre>
reverse :: SemiSequence seq => seq -> seq
-- | <a>find</a> takes a predicate and a sequence and returns the first
-- element in the sequence matching the predicate, or <a>Nothing</a> if
-- there isn't an element that matches the predicate.
--
-- <pre>
-- > <a>find</a> (== 5) [1 .. 10]
-- <a>Just</a> 5
--
-- > <a>find</a> (== 15) [1 .. 10]
-- <a>Nothing</a>
-- </pre>
find :: SemiSequence seq => (Element seq -> Bool) -> seq -> Maybe (Element seq)
-- | Sort a sequence using an supplied element ordering function.
--
-- <pre>
-- > let compare' x y = case <a>compare</a> x y of LT -> GT; EQ -> EQ; GT -> LT
-- > <a>sortBy</a> compare' [5,3,6,1,2,4]
-- [6,5,4,3,2,1]
-- </pre>
sortBy :: SemiSequence seq => (Element seq -> Element seq -> Ordering) -> seq -> seq
-- | Prepend an element onto a sequence.
--
-- <pre>
-- > 4 `<a>cons</a>` [1,2,3]
-- [4,1,2,3]
-- </pre>
cons :: SemiSequence seq => Element seq -> seq -> seq
-- | Append an element onto a sequence.
--
-- <pre>
-- > [1,2,3] `<a>snoc</a>` 4
-- [1,2,3,4]
-- </pre>
snoc :: SemiSequence seq => seq -> Element seq -> seq
-- | Create a sequence from a single element.
--
-- <pre>
-- > <a>singleton</a> <tt>a</tt> :: <tt>String</tt>
-- "a"
-- > <a>singleton</a> <tt>a</tt> :: <tt>Vector</tt> <a>Char</a>
-- <a>fromList</a> "a"
-- </pre>
singleton :: IsSequence seq => Element seq -> seq
-- | Sequence Laws:
--
-- <pre>
-- <a>fromList</a> . <a>otoList</a> = <a>id</a>
-- <a>fromList</a> (x <> y) = <a>fromList</a> x <> <a>fromList</a> y
-- <a>otoList</a> (<a>fromList</a> x <> <a>fromList</a> y) = x <> y
-- </pre>
class (Monoid seq, MonoTraversable seq, SemiSequence seq, MonoPointed seq) => IsSequence seq where fromList = mconcat . fmap singleton lengthIndex = fromIntegral . olength64 break f = (fromList *** fromList) . break f . otoList span f = (fromList *** fromList) . span f . otoList dropWhile f = fromList . dropWhile f . otoList takeWhile f = fromList . takeWhile f . otoList splitAt i = (fromList *** fromList) . genericSplitAt i . otoList unsafeSplitAt i seq = (unsafeTake i seq, unsafeDrop i seq) take i = fst . splitAt i unsafeTake = take drop i = snd . splitAt i unsafeDrop = drop dropEnd i s = fst $ splitAt (lengthIndex s - i) s partition f = (fromList *** fromList) . partition f . otoList uncons = fmap (second fromList) . uncons . otoList unsnoc = fmap (first fromList) . unsnoc . otoList filter f = fromList . filter f . otoList filterM f = liftM fromList . filterM f . otoList replicate i = fromList . genericReplicate i replicateM i = liftM fromList . replicateM (fromIntegral i) groupBy f = fmap fromList . groupBy f . otoList groupAllOn f = fmap fromList . groupAllOn f . otoList subsequences = map fromList . subsequences . otoList permutations = map fromList . permutations . otoList tailEx = snd . maybe (error "Data.Sequences.tailEx") id . uncons tailMay seq | onull seq = Nothing | otherwise = Just (tailEx seq) initEx = fst . maybe (error "Data.Sequences.initEx") id . unsnoc initMay seq | onull seq = Nothing | otherwise = Just (initEx seq) unsafeTail = tailEx unsafeInit = initEx index seq' idx = headMay (drop idx seq') indexEx seq' idx = maybe (error "Data.Sequences.indexEx") id (index seq' idx) unsafeIndex = indexEx splitWhen = defaultSplitWhen
-- | Convert a list to a sequence.
--
-- <pre>
-- > <a>fromList</a> [<tt>a</tt>, <tt>b</tt>, <tt>c</tt>] :: Text
-- "abc"
-- </pre>
fromList :: IsSequence seq => [Element seq] -> seq
-- | <a>lengthIndex</a> returns the length of a sequence as
-- <tt><a>Index</a> seq</tt>.
lengthIndex :: IsSequence seq => seq -> Index seq
-- | <a>break</a> applies a predicate to a sequence, and returns a tuple
-- where the first element is the longest prefix (possibly empty) of
-- elements that <i>do not satisfy</i> the predicate. The second element
-- of the tuple is the remainder of the sequence.
--
-- <tt><a>break</a> p</tt> is equivalent to <tt><a>span</a> (<tt>not</tt>
-- . p)</tt>
--
-- <pre>
-- > <a>break</a> (> 3) (<a>fromList</a> [1,2,3,4,1,2,3,4] :: <tt>Vector</tt> <a>Int</a>)
-- (fromList [1,2,3],fromList [4,1,2,3,4])
--
-- > <a>break</a> (< <tt>z</tt>) (<a>fromList</a> "abc" :: <tt>Text</tt>)
-- ("","abc")
--
-- > <a>break</a> (> <tt>z</tt>) (<a>fromList</a> "abc" :: <tt>Text</tt>)
-- ("abc","")
-- </pre>
break :: IsSequence seq => (Element seq -> Bool) -> seq -> (seq, seq)
-- | <a>span</a> applies a predicate to a sequence, and returns a tuple
-- where the first element is the longest prefix (possibly empty) that
-- <i>does satisfy</i> the predicate. The second element of the tuple is
-- the remainder of the sequence.
--
-- <tt><a>span</a> p xs</tt> is equivalent to <tt>(<a>takeWhile</a> p xs,
-- <a>dropWhile</a> p xs)</tt>
--
-- <pre>
-- > <a>span</a> (< 3) (<a>fromList</a> [1,2,3,4,1,2,3,4] :: <tt>Vector</tt> <a>Int</a>)
-- (fromList [1,2],fromList [3,4,1,2,3,4])
--
-- > <a>span</a> (< <tt>z</tt>) (<a>fromList</a> "abc" :: <tt>Text</tt>)
-- ("abc","")
--
-- > <a>span</a> (< 0) <a>1,2,3</a>
-- </pre>
span :: IsSequence seq => (Element seq -> Bool) -> seq -> (seq, seq)
-- | <a>dropWhile</a> returns the suffix remaining after <a>takeWhile</a>.
--
-- <pre>
-- > <a>dropWhile</a> (< 3) [1,2,3,4,5,1,2,3]
-- [3,4,5,1,2,3]
--
-- > <a>dropWhile</a> (< <tt>z</tt>) (<a>fromList</a> "abc" :: <tt>Text</tt>)
-- ""
-- </pre>
dropWhile :: IsSequence seq => (Element seq -> Bool) -> seq -> seq
-- | <a>takeWhile</a> applies a predicate to a sequence, and returns the
-- longest prefix (possibly empty) of the sequence of elements that
-- <i>satisfy</i> the predicate.
--
-- <pre>
-- > <a>takeWhile</a> (< 3) [1,2,3,4,5,1,2,3]
-- [1,2]
--
-- > <a>takeWhile</a> (< <tt>z</tt>) (<a>fromList</a> "abc" :: <tt>Text</tt>)
-- "abc"
-- </pre>
takeWhile :: IsSequence seq => (Element seq -> Bool) -> seq -> seq
-- | <tt><a>splitAt</a> n se</tt> returns a tuple where the first element
-- is the prefix of the sequence <tt>se</tt> with length <tt>n</tt>, and
-- the second element is the remainder of the sequence.
--
-- <pre>
-- > <a>splitAt</a> 6 "Hello world!"
-- ("Hello ","world!")
--
-- > <a>splitAt</a> 3 (<a>fromList</a> [1,2,3,4,5] :: <tt>Vector</tt> <a>Int</a>)
-- (fromList [1,2,3],fromList [4,5])
-- </pre>
splitAt :: IsSequence seq => Index seq -> seq -> (seq, seq)
-- | Equivalent to <a>splitAt</a>.
unsafeSplitAt :: IsSequence seq => Index seq -> seq -> (seq, seq)
-- | <tt><a>take</a> n</tt> returns the prefix of a sequence of length
-- <tt>n</tt>, or the sequence itself if <tt>n > <a>olength</a>
-- seq</tt>.
--
-- <pre>
-- > <a>take</a> 3 "abcdefg"
-- "abc"
-- > <a>take</a> 4 (<a>fromList</a> [1,2,3,4,5,6] :: <tt>Vector</tt> <a>Int</a>)
-- fromList [1,2,3,4]
-- </pre>
take :: IsSequence seq => Index seq -> seq -> seq
-- | Equivalent to <a>take</a>.
unsafeTake :: IsSequence seq => Index seq -> seq -> seq
-- | <tt><a>drop</a> n</tt> returns the suffix of a sequence after the
-- first <tt>n</tt> elements, or an empty sequence if <tt>n >
-- <a>olength</a> seq</tt>.
--
-- <pre>
-- > <a>drop</a> 3 "abcdefg"
-- "defg"
-- > <a>drop</a> 4 (<a>fromList</a> [1,2,3,4,5,6] :: <tt>Vector</tt> <a>Int</a>)
-- fromList [5,6]
-- </pre>
drop :: IsSequence seq => Index seq -> seq -> seq
-- | Equivalent to <a>drop</a>
unsafeDrop :: IsSequence seq => Index seq -> seq -> seq
-- | Same as <a>drop</a> but drops from the end of the sequence instead.
--
-- <pre>
-- > <a>dropEnd</a> 3 "abcdefg"
-- "abcd"
-- > <a>dropEnd</a> 4 (<a>fromList</a> [1,2,3,4,5,6] :: <tt>Vector</tt> <a>Int</a>)
-- fromList [1,2]
-- </pre>
dropEnd :: IsSequence seq => Index seq -> seq -> seq
-- | <a>partition</a> takes a predicate and a sequence and returns the pair
-- of sequences of elements which do and do not satisfy the predicate.
--
-- <pre>
-- <a>partition</a> p se = (<a>filter</a> p se, <a>filter</a> (<tt>not</tt> . p) se)
-- </pre>
partition :: IsSequence seq => (Element seq -> Bool) -> seq -> (seq, seq)
-- | <a>uncons</a> returns the tuple of the first element of a sequence and
-- the rest of the sequence, or <a>Nothing</a> if the sequence is empty.
--
-- <pre>
-- > <a>uncons</a> (<a>fromList</a> [1,2,3,4] :: <tt>Vector</tt> <a>Int</a>)
-- <a>Just</a> (1,fromList [2,3,4])
--
-- > <a>uncons</a> ([] :: [<a>Int</a>])
-- <a>Nothing</a>
-- </pre>
uncons :: IsSequence seq => seq -> Maybe (Element seq, seq)
-- | <a>unsnoc</a> returns the tuple of the init of a sequence and the last
-- element, or <a>Nothing</a> if the sequence is empty.
--
-- <pre>
-- > <a>unsnoc</a> (<a>fromList</a> [1,2,3,4] :: <tt>Vector</tt> <a>Int</a>)
-- <a>Just</a> (fromList [1,2,3],4)
--
-- > <a>unsnoc</a> ([] :: [<a>Int</a>])
-- <a>Nothing</a>
-- </pre>
unsnoc :: IsSequence seq => seq -> Maybe (seq, Element seq)
-- | <a>filter</a> given a predicate returns a sequence of all elements
-- that satisfy the predicate.
--
-- <pre>
-- > <a>filter</a> (< 5) [1 .. 10]
-- [1,2,3,4]
-- </pre>
filter :: IsSequence seq => (Element seq -> Bool) -> seq -> seq
-- | The monadic version of <a>filter</a>.
filterM :: (IsSequence seq, Monad m) => (Element seq -> m Bool) -> seq -> m seq
-- | <tt><a>replicate</a> n x</tt> is a sequence of length <tt>n</tt> with
-- <tt>x</tt> as the value of every element.
--
-- <pre>
-- > <a>replicate</a> 10 <tt>a</tt> :: Text
-- "aaaaaaaaaa"
-- </pre>
replicate :: IsSequence seq => Index seq -> Element seq -> seq
-- | The monadic version of <a>replicateM</a>.
replicateM :: (IsSequence seq, Monad m) => Index seq -> m (Element seq) -> m seq
-- | <a>group</a> takes a sequence and returns a list of sequences such
-- that the concatenation of the result is equal to the argument. Each
-- subsequence in the result contains only equal elements, using the
-- supplied equality test.
--
-- <pre>
-- > <a>groupBy</a> (==) <a>Mississippi</a>
-- [<a>M</a>,"i","ss","i","ss","i","pp","i"]
-- </pre>
groupBy :: IsSequence seq => (Element seq -> Element seq -> Bool) -> seq -> [seq]
-- | Similar to standard <a>groupBy</a>, but operates on the whole
-- collection, not just the consecutive items.
groupAllOn :: (IsSequence seq, Eq b) => (Element seq -> b) -> seq -> [seq]
-- | <a>subsequences</a> returns a list of all subsequences of the
-- argument.
--
-- <pre>
-- > <a>subsequences</a> "abc"
-- ["","a","b","ab","c","ac","bc","abc"]
-- </pre>
subsequences :: IsSequence seq => seq -> [seq]
-- | <a>permutations</a> returns a list of all permutations of the
-- argument.
--
-- <pre>
-- > <a>permutations</a> "abc"
-- ["abc","bac","cba","bca","cab","acb"]
-- </pre>
permutations :: IsSequence seq => seq -> [seq]
-- | <b>Unsafe</b>
--
-- Get the tail of a sequence, throw an exception if the sequence is
-- empty.
--
-- <pre>
-- > <a>tailEx</a> [1,2,3]
-- [2,3]
-- </pre>
tailEx :: IsSequence seq => seq -> seq
-- | Safe version of <a>tailEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
tailMay :: IsSequence seq => seq -> Maybe seq
-- | <b>Unsafe</b>
--
-- Get the init of a sequence, throw an exception if the sequence is
-- empty.
--
-- <pre>
-- > <a>initEx</a> [1,2,3]
-- [1,2]
-- </pre>
initEx :: IsSequence seq => seq -> seq
-- | Safe version of <a>initEx</a>.
--
-- Returns <a>Nothing</a> instead of throwing an exception when
-- encountering an empty monomorphic container.
initMay :: (IsSequence seq, IsSequence seq) => seq -> Maybe seq
-- | Equivalent to <a>tailEx</a>.
unsafeTail :: IsSequence seq => seq -> seq
-- | Equivalent to <a>initEx</a>.
unsafeInit :: IsSequence seq => seq -> seq
-- | Get the element of a sequence at a certain index, returns
-- <a>Nothing</a> if that index does not exist.
--
-- <pre>
-- > <a>index</a> (<a>fromList</a> [1,2,3] :: <tt>Vector</tt> <a>Int</a>) 1
-- <a>Just</a> 2
-- > <a>index</a> (<a>fromList</a> [1,2,3] :: <tt>Vector</tt> <a>Int</a>) 4
-- <a>Nothing</a>
-- </pre>
index :: IsSequence seq => seq -> Index seq -> Maybe (Element seq)
-- | <b>Unsafe</b>
--
-- Get the element of a sequence at a certain index, throws an exception
-- if the index does not exist.
indexEx :: IsSequence seq => seq -> Index seq -> Element seq
-- | Equivalent to <a>indexEx</a>.
unsafeIndex :: IsSequence seq => seq -> Index seq -> Element seq
-- | <a>splitWhen</a> splits a sequence into components delimited by
-- separators, where the predicate returns True for a separator element.
-- The resulting components do not contain the separators. Two adjacent
-- separators result in an empty component in the output. The number of
-- resulting components is greater by one than number of separators.
--
-- Since 0.9.3
splitWhen :: IsSequence seq => (Element seq -> Bool) -> seq -> [seq]
-- | Use <a>Data.List</a>'s implementation of <a>find</a>.
defaultFind :: MonoFoldable seq => (Element seq -> Bool) -> seq -> Maybe (Element seq)
-- | Use <a>Data.List</a>'s implementation of <a>intersperse</a>.
defaultIntersperse :: IsSequence seq => Element seq -> seq -> seq
-- | Use <a>Data.List</a>'s implementation of <a>reverse</a>.
defaultReverse :: IsSequence seq => seq -> seq
-- | Use <a>Data.List</a>'s implementation of <a>sortBy</a>.
defaultSortBy :: IsSequence seq => (Element seq -> Element seq -> Ordering) -> seq -> seq
-- | Use <a>splitWhen</a> from <a>Data.List.Split</a>
defaultSplitWhen :: IsSequence seq => (Element seq -> Bool) -> seq -> [seq]
-- | Sort a vector using an supplied element ordering function.
vectorSortBy :: Vector v e => (e -> e -> Ordering) -> v e -> v e
-- | Sort a vector.
vectorSort :: (Vector v e, Ord e) => v e -> v e
-- | Use <a>Data.List</a>'s <a>:</a> to prepend an element to a sequence.
defaultCons :: IsSequence seq => Element seq -> seq -> seq
-- | Use <a>Data.List</a>'s <a>++</a> to append an element to a sequence.
defaultSnoc :: IsSequence seq => seq -> Element seq -> seq
-- | like Data.List.tail, but an input of <a>mempty</a> returns
-- <a>mempty</a>
tailDef :: IsSequence seq => seq -> seq
-- | like Data.List.init, but an input of <a>mempty</a> returns
-- <a>mempty</a>
initDef :: IsSequence seq => seq -> seq
-- | <tt><a>splitElem</a></tt> splits a sequence into components delimited
-- by separator element. It's equivalent to <a>splitWhen</a> with
-- equality predicate:
--
-- <pre>
-- splitElem sep === splitWhen (== sep)
-- </pre>
--
-- Since 0.9.3
splitElem :: (IsSequence seq, Eq (Element seq)) => Element seq -> seq -> [seq]
-- | <tt><a>splitSeq</a></tt> splits a sequence into components delimited
-- by separator subsequence. <a>splitSeq</a> is the right inverse of
-- <tt>intercalate</tt>:
--
-- <pre>
-- ointercalate x . splitSeq x === id
-- </pre>
--
-- <a>splitElem</a> can be considered a special case of <a>splitSeq</a>
--
-- <pre>
-- splitSeq (singleton sep) === splitElem sep
-- </pre>
--
-- <tt><a>splitSeq</a> mempty</tt> is another special case: it splits
-- just before each element, and in line with <a>splitWhen</a> rules, it
-- has at least one output component:
--
-- <pre>
-- > <a>splitSeq</a> "" ""
-- [""]
-- > <a>splitSeq</a> "" "a"
-- ["", "a"]
-- > <a>splitSeq</a> "" "ab"
-- ["", "a", "b"]
-- </pre>
--
-- Since 0.9.3
splitSeq :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> [seq]
-- | <tt><a>replaceSeq</a> old new</tt> replaces all <tt>old</tt>
-- subsequences with <tt>new</tt>.
--
-- <pre>
-- replaceSeq old new === ointercalate new . splitSeq old
-- </pre>
replaceSeq :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> seq -> seq
-- | <a>stripPrefix</a> drops the given prefix from a sequence. It returns
-- <a>Nothing</a> if the sequence did not start with the prefix given, or
-- <a>Just</a> the sequence after the prefix, if it does.
--
-- <pre>
-- > <a>stripPrefix</a> "foo" "foobar"
-- <a>Just</a> "bar"
-- > <a>stripPrefix</a> "abc" "foobar"
-- <a>Nothing</a>
-- </pre>
stripPrefix :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> Maybe seq
-- | <a>stripSuffix</a> drops the given suffix from a sequence. It returns
-- <a>Nothing</a> if the sequence did not end with the suffix given, or
-- <a>Just</a> the sequence before the suffix, if it does.
--
-- <pre>
-- > <a>stripSuffix</a> "bar" "foobar"
-- <a>Just</a> "foo"
-- > <a>stripSuffix</a> "abc" "foobar"
-- <a>Nothing</a>
-- </pre>
stripSuffix :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> Maybe seq
-- | <a>ensurePrefix</a> will add a prefix to a sequence if it doesn't
-- exist, and otherwise have no effect.
--
-- <pre>
-- > <a>ensurePrefix</a> "foo" "foobar"
-- "foobar"
-- > <a>ensurePrefix</a> "abc" "foobar"
-- "abcfoobar"
-- </pre>
ensurePrefix :: (Eq (Element seq), IsSequence seq) => seq -> seq -> seq
-- | Append a suffix to a sequence, unless it already has that suffix.
--
-- <pre>
-- > <a>ensureSuffix</a> "bar" "foobar"
-- "foobar"
-- > <a>ensureSuffix</a> "abc" "foobar"
-- "foobarabc"
-- </pre>
ensureSuffix :: (Eq (Element seq), IsSequence seq) => seq -> seq -> seq
-- | <a>isPrefixOf</a> takes two sequences and returns <a>True</a> if the
-- first sequence is a prefix of the second.
isPrefixOf :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> Bool
-- | <a>isSuffixOf</a> takes two sequences and returns <a>True</a> if the
-- first sequence is a suffix of the second.
isSuffixOf :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> Bool
-- | <a>isInfixOf</a> takes two sequences and returns <tt>true</tt> if the
-- first sequence is contained, wholly and intact, anywhere within the
-- second.
isInfixOf :: (IsSequence seq, Eq (Element seq)) => seq -> seq -> Bool
-- | Equivalent to <tt><a>groupBy</a> (==)</tt>
group :: (IsSequence seq, Eq (Element seq)) => seq -> [seq]
-- | Similar to standard <a>group</a>, but operates on the whole
-- collection, not just the consecutive items.
--
-- Equivalent to <tt><a>groupAllOn</a> id</tt>
groupAll :: (IsSequence seq, Eq (Element seq)) => seq -> [seq]
delete :: (IsSequence seq, Eq (Element seq)) => Element seq -> seq -> seq
deleteBy :: (IsSequence seq, Eq (Element seq)) => (Element seq -> Element seq -> Bool) -> Element seq -> seq -> seq
splitElemStrictBS :: Word8 -> ByteString -> [ByteString]
stripPrefixStrictBS :: ByteString -> ByteString -> Maybe ByteString
stripSuffixStrictBS :: ByteString -> ByteString -> Maybe ByteString
splitSeqLazyBS :: Word8 -> ByteString -> [ByteString]
stripPrefixLazyBS :: ByteString -> ByteString -> Maybe ByteString
stripSuffixLazyBS :: ByteString -> ByteString -> Maybe ByteString
splitSeqStrictText :: Text -> Text -> [Text]
replaceSeqStrictText :: Text -> Text -> Text -> Text
splitSeqLazyText :: Text -> Text -> [Text]
replaceSeqLazyText :: Text -> Text -> Text -> Text
-- | Sort a ordered sequence.
--
-- <pre>
-- > <a>sort</a> [4,3,1,2]
-- [1,2,3,4]
-- </pre>
sort :: (IsSequence seq, Ord (Element seq)) => seq -> seq
-- | A typeclass for sequences whose elements are <a>Char</a>s.
class (IsSequence t, IsString t, Element t ~ Char) => Textual t where breakWord = fmap (dropWhile isSpace) . break isSpace breakLine = (killCR *** drop 1) . break (== '\n') where killCR t = case unsnoc t of { Just (t', '\r') -> t' _ -> t }
-- | Break up a textual sequence into a list of words, which were delimited
-- by white space.
--
-- <pre>
-- > <a>words</a> "abc def ghi"
-- ["abc","def","ghi"]
-- </pre>
words :: Textual t => t -> [t]
-- | Join a list of textual sequences using seperating spaces.
--
-- <pre>
-- > <a>unwords</a> ["abc","def","ghi"]
-- "abc def ghi"
-- </pre>
unwords :: (Textual t, Element seq ~ t, MonoFoldable seq) => seq -> t
-- | Break up a textual sequence at newline characters.
--
-- <pre>
-- > <a>lines</a> "hello\nworld"
-- ["hello","world"]
-- </pre>
lines :: Textual t => t -> [t]
-- | Join a list of textual sequences using newlines.
--
-- <pre>
-- > <a>unlines</a> ["abc","def","ghi"]
-- "abc\ndef\nghi"
-- </pre>
unlines :: (Textual t, Element seq ~ t, MonoFoldable seq) => seq -> t
-- | Convert a textual sequence to lower-case.
--
-- <pre>
-- > <a>toLower</a> "HELLO WORLD"
-- "hello world"
-- </pre>
toLower :: Textual t => t -> t
-- | Convert a textual sequence to upper-case.
--
-- <pre>
-- > <a>toUpper</a> "hello world"
-- "HELLO WORLD"
-- </pre>
toUpper :: Textual t => t -> t
-- | Convert a textual sequence to folded-case.
--
-- Slightly different from <a>toLower</a>, see
-- <tt><a>Data.Text</a>.<a>toCaseFold</a></tt>
toCaseFold :: Textual t => t -> t
-- | Split a textual sequence into two parts, split at the first space.
--
-- <pre>
-- > <a>breakWord</a> "hello world"
-- ("hello","world")
-- </pre>
breakWord :: Textual t => t -> (t, t)
-- | Split a textual sequence into two parts, split at the newline.
--
-- <pre>
-- > <a>breakLine</a> "abc\ndef"
-- ("abc","def")
-- </pre>
breakLine :: Textual t => t -> (t, t)
-- | Takes all of the <a>Just</a> values from a sequence of <tt>Maybe
-- t</tt>s and concatenates them into an unboxed sequence of <tt>t</tt>s.
--
-- Since 0.6.2
catMaybes :: (IsSequence (f (Maybe t)), Functor f, Element (f (Maybe t)) ~ Maybe t) => f (Maybe t) -> f t
-- | Same as <tt>sortBy . comparing</tt>.
--
-- Since 0.7.0
sortOn :: (Ord o, SemiSequence seq) => (Element seq -> o) -> seq -> seq
-- | Lazy sequences containing strict chunks of data.
class (IsSequence lazy, IsSequence strict) => LazySequence lazy strict | lazy -> strict, strict -> lazy
toChunks :: LazySequence lazy strict => lazy -> [strict]
fromChunks :: LazySequence lazy strict => [strict] -> lazy
toStrict :: LazySequence lazy strict => lazy -> strict
fromStrict :: LazySequence lazy strict => strict -> lazy
-- | Synonym for <a>fromList</a>
pack :: IsSequence seq => [Element seq] -> seq
-- | Synonym for <a>otoList</a>
unpack :: MonoFoldable mono => mono -> [Element mono]
-- | Repack from one type to another, dropping to a list in the middle.
--
-- <tt>repack = pack . unpack</tt>.
repack :: (MonoFoldable a, IsSequence b, Element a ~ Element b) => a -> b
-- | Textual data which can be encoded to and decoded from UTF8.
class (Textual textual, IsSequence binary) => Utf8 textual binary | textual -> binary, binary -> textual
-- | Encode from textual to binary using UTF-8 encoding
encodeUtf8 :: Utf8 textual binary => textual -> binary
-- | Note that this function is required to be pure. In the case of a
-- decoding error, Unicode replacement characters must be used.
decodeUtf8 :: Utf8 textual binary => binary -> textual
instance Data.Sequences.SemiSequence [a]
instance Data.Sequences.IsSequence [a]
instance Data.Sequences.SemiSequence (Data.List.NonEmpty.NonEmpty a)
instance Data.Sequences.SemiSequence Data.ByteString.Internal.ByteString
instance Data.Sequences.IsSequence Data.ByteString.Internal.ByteString
instance Data.Sequences.SemiSequence Data.Text.Internal.Text
instance Data.Sequences.IsSequence Data.Text.Internal.Text
instance Data.Sequences.SemiSequence Data.ByteString.Lazy.Internal.ByteString
instance Data.Sequences.IsSequence Data.ByteString.Lazy.Internal.ByteString
instance Data.Sequences.SemiSequence Data.Text.Internal.Lazy.Text
instance Data.Sequences.IsSequence Data.Text.Internal.Lazy.Text
instance Data.Sequences.SemiSequence (Data.Sequence.Seq a)
instance Data.Sequences.IsSequence (Data.Sequence.Seq a)
instance Data.Sequences.SemiSequence (Data.Vector.Vector a)
instance Data.Sequences.IsSequence (Data.Vector.Vector a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.Sequences.SemiSequence (Data.Vector.Unboxed.Base.Vector a)
instance Data.Vector.Unboxed.Base.Unbox a => Data.Sequences.IsSequence (Data.Vector.Unboxed.Base.Vector a)
instance Foreign.Storable.Storable a => Data.Sequences.SemiSequence (Data.Vector.Storable.Vector a)
instance Foreign.Storable.Storable a => Data.Sequences.IsSequence (Data.Vector.Storable.Vector a)
instance c ~ GHC.Types.Char => Data.Sequences.Textual [c]
instance Data.Sequences.Textual Data.Text.Internal.Text
instance Data.Sequences.Textual Data.Text.Internal.Lazy.Text
instance Data.Sequences.LazySequence Data.ByteString.Lazy.Internal.ByteString Data.ByteString.Internal.ByteString
instance Data.Sequences.LazySequence Data.Text.Internal.Lazy.Text Data.Text.Internal.Text
instance (c ~ GHC.Types.Char, w ~ GHC.Word.Word8) => Data.Sequences.Utf8 [c] [w]
instance Data.Sequences.Utf8 Data.Text.Internal.Text Data.ByteString.Internal.ByteString
instance Data.Sequences.Utf8 Data.Text.Internal.Lazy.Text Data.ByteString.Lazy.Internal.ByteString
-- | <a>Data.NonNull</a> extends the concepts from
-- <a>Data.List.NonEmpty</a> to any <a>MonoFoldable</a>.
--
-- <a>NonNull</a> is a newtype wrapper for a container with 1 or more
-- elements.
module Data.NonNull
-- | A monomorphic container that is not null.
data NonNull mono
-- | <b>Safely</b> convert from an <b>unsafe</b> monomorphic container to a
-- <b>safe</b> non-null monomorphic container.
fromNullable :: MonoFoldable mono => mono -> Maybe (NonNull mono)
-- | <b>Unsafely</b> convert from an <b>unsafe</b> monomorphic container to
-- a <b>safe</b> non-null monomorphic container.
--
-- Throws an exception if the monomorphic container is empty.
impureNonNull :: MonoFoldable mono => mono -> NonNull mono
-- | Old synonym for <a>impureNonNull</a>
-- | <i>Deprecated: Please use the more explicit impureNonNull instead</i>
nonNull :: MonoFoldable mono => mono -> NonNull mono
-- | <b>Safely</b> convert from a non-null monomorphic container to a
-- nullable monomorphic container.
toNullable :: NonNull mono -> mono
-- | <b>Safely</b> convert from a <tt>NonEmpty</tt> list to a non-null
-- monomorphic container.
fromNonEmpty :: IsSequence seq => NonEmpty (Element seq) -> NonNull seq
-- | Prepend an element to a <a>SemiSequence</a>, creating a non-null
-- <a>SemiSequence</a>.
--
-- Generally this uses cons underneath. cons is not efficient for most
-- data structures.
--
-- Alternatives:
--
-- <ul>
-- <li>if you don't need to cons, use <a>fromNullable</a> or
-- <a>nonNull</a> if you can create your structure in one go.</li>
-- <li>if you need to cons, you might be able to start off with an
-- efficient data structure such as a <tt>NonEmpty</tt> List.
-- <tt>fronNonEmpty</tt> will convert that to your data structure using
-- the structure's fromList function.</li>
-- </ul>
ncons :: SemiSequence seq => Element seq -> seq -> NonNull seq
-- | Extract the first element of a sequnce and the rest of the non-null
-- sequence if it exists.
nuncons :: IsSequence seq => NonNull seq -> (Element seq, Maybe (NonNull seq))
-- | Same as <a>nuncons</a> with no guarantee that the rest of the sequence
-- is non-null.
splitFirst :: IsSequence seq => NonNull seq -> (Element seq, seq)
-- | Equivalent to <tt><a>Data.Sequence</a>.<a>filter</a></tt>, but works
-- on non-nullable sequences.
nfilter :: IsSequence seq => (Element seq -> Bool) -> NonNull seq -> seq
-- | Equivalent to <tt><a>Data.Sequence</a>.<a>filterM</a></tt>, but works
-- on non-nullable sequences.
nfilterM :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> NonNull seq -> m seq
-- | Equivalent to <tt><a>Data.Sequence</a>.<a>replicate</a></tt>
--
-- <tt>i</tt> must be <tt>> 0</tt>
--
-- <tt>i <= 0</tt> is treated the same as providing <tt>1</tt>
nReplicate :: IsSequence seq => Index seq -> Element seq -> NonNull seq
-- | Return the first element of a monomorphic container.
--
-- Safe version of <a>headEx</a>, only works on monomorphic containers
-- wrapped in a <a>NonNull</a>.
head :: MonoFoldable mono => NonNull mono -> Element mono
-- | <b>Safe</b> version of <a>tailEx</a>, only working on non-nullable
-- sequences.
tail :: IsSequence seq => NonNull seq -> seq
-- | Return the last element of a monomorphic container.
--
-- Safe version of <a>lastEx</a>, only works on monomorphic containers
-- wrapped in a <a>NonNull</a>.
last :: MonoFoldable mono => NonNull mono -> Element mono
-- | <b>Safe</b> version of <a>initEx</a>, only working on non-nullable
-- sequences.
init :: IsSequence seq => NonNull seq -> seq
-- | Map each element of a monomorphic container to a semigroup, and
-- combine the results.
--
-- Safe version of <a>ofoldMap1Ex</a>, only works on monomorphic
-- containers wrapped in a <a>NonNull</a>.
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons ("hello", 1 :: <a>Integer</a>) [(" world", 2)]
-- > <a>ofoldMap1</a> <a>fst</a> xs
-- "hello world"
-- </pre>
ofoldMap1 :: (MonoFoldable mono, Semigroup m) => (Element mono -> m) -> NonNull mono -> m
-- | Join a monomorphic container, whose elements are <a>Semigroup</a>s,
-- together.
--
-- Safe, only works on monomorphic containers wrapped in a
-- <a>NonNull</a>.
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons "a" ["b", "c"]
-- > xs
-- <a>NonNull</a> {toNullable = ["a","b","c"]}
--
-- > <a>ofold1</a> xs
-- "abc"
-- </pre>
ofold1 :: (MonoFoldable mono, Semigroup (Element mono)) => NonNull mono -> Element mono
-- | Right-associative fold of a monomorphic container with no base
-- element.
--
-- Safe version of <a>ofoldr1Ex</a>, only works on monomorphic containers
-- wrapped in a <a>NonNull</a>.
--
-- <pre>
-- <a>foldr1</a> f = <a>Prelude</a>.<a>foldr1</a> f . <a>otoList</a>
-- </pre>
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons "a" ["b", "c"]
-- > <a>ofoldr1</a> (++) xs
-- "abc"
-- </pre>
ofoldr1 :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono
-- | Strict left-associative fold of a monomorphic container with no base
-- element.
--
-- Safe version of <a>ofoldl1Ex'</a>, only works on monomorphic
-- containers wrapped in a <a>NonNull</a>.
--
-- <pre>
-- <tt>foldl1'</tt> f = <a>Prelude</a>.<a>foldl1'</a> f . <a>otoList</a>
-- </pre>
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons "a" ["b", "c"]
-- > <a>ofoldl1'</a> (++) xs
-- "abc"
-- </pre>
ofoldl1' :: MonoFoldable mono => (Element mono -> Element mono -> Element mono) -> NonNull mono -> Element mono
-- | Get the maximum element of a monomorphic container.
--
-- Safe version of <a>maximumEx</a>, only works on monomorphic containers
-- wrapped in a <a>NonNull</a>.
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons 1 [2, 3 :: Int]
-- > <a>maximum</a> xs
-- 3
-- </pre>
maximum :: (MonoFoldable mono, Ord (Element mono)) => NonNull mono -> Element mono
-- | Get the maximum element of a monomorphic container, using a supplied
-- element ordering function.
--
-- Safe version of <a>maximumByEx</a>, only works on monomorphic
-- containers wrapped in a <a>NonNull</a>.
maximumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono
-- | Get the minimum element of a monomorphic container.
--
-- Safe version of <a>minimumEx</a>, only works on monomorphic containers
-- wrapped in a <a>NonNull</a>.
--
-- <h4><b>Examples</b></h4>
--
-- <pre>
-- > let xs = ncons 1 [2, 3 :: Int]
-- > <a>minimum</a> xs
-- 1
-- </pre>
minimum :: (MonoFoldable mono, Ord (Element mono)) => NonNull mono -> Element mono
-- | Get the minimum element of a monomorphic container, using a supplied
-- element ordering function.
--
-- Safe version of <a>minimumByEx</a>, only works on monomorphic
-- containers wrapped in a <a>NonNull</a>.
minimumBy :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> NonNull mono -> Element mono
-- | Prepend an element to a non-null <a>SemiSequence</a>.
(<|) :: SemiSequence seq => Element seq -> NonNull seq -> NonNull seq
infixr 5 <|
-- | Specializes <a>fromNonEmpty</a> to lists only.
toMinList :: NonEmpty a -> NonNull [a]
-- | <a>fmap</a> over the underlying container in a <a>NonNull</a>.
mapNonNull :: (Functor f, MonoFoldable (f b)) => (a -> b) -> NonNull (f a) -> NonNull (f b)
-- | Containers which, when two values are combined, the combined length is
-- no less than the larger of the two inputs. In code:
--
-- <pre>
-- olength (x <> y) >= max (olength x) (olength y)
-- </pre>
--
-- This class has no methods, and is simply used to assert that this law
-- holds, in order to provide guarantees of correctness (see, for
-- instance, <a>Data.NonNull</a>).
--
-- This should have a <tt>Semigroup</tt> superclass constraint, however,
-- due to <tt>Semigroup</tt> only recently moving to base, some packages
-- do not provide instances.
class MonoFoldable mono => GrowingAppend mono
instance Data.Data.Data mono => Data.Data.Data (Data.NonNull.NonNull mono)
instance GHC.Show.Show mono => GHC.Show.Show (Data.NonNull.NonNull mono)
instance GHC.Read.Read mono => GHC.Read.Read (Data.NonNull.NonNull mono)
instance GHC.Classes.Ord mono => GHC.Classes.Ord (Data.NonNull.NonNull mono)
instance GHC.Classes.Eq mono => GHC.Classes.Eq (Data.NonNull.NonNull mono)
instance GHC.Show.Show Data.NonNull.NullError
instance Data.MonoTraversable.MonoFunctor mono => Data.MonoTraversable.MonoFunctor (Data.NonNull.NonNull mono)
instance Data.MonoTraversable.MonoFoldable mono => Data.MonoTraversable.MonoFoldable (Data.NonNull.NonNull mono)
instance GHC.Exception.Exception Data.NonNull.NullError
instance Data.MonoTraversable.MonoTraversable mono => Data.MonoTraversable.MonoTraversable (Data.NonNull.NonNull mono)
instance Data.MonoTraversable.GrowingAppend mono => Data.MonoTraversable.GrowingAppend (Data.NonNull.NonNull mono)
instance (Data.Semigroup.Semigroup mono, Data.MonoTraversable.GrowingAppend mono) => Data.Semigroup.Semigroup (Data.NonNull.NonNull mono)
instance Data.Sequences.SemiSequence seq => Data.Sequences.SemiSequence (Data.NonNull.NonNull seq)
instance Data.MonoTraversable.MonoPointed mono => Data.MonoTraversable.MonoPointed (Data.NonNull.NonNull mono)
instance Data.Sequences.IsSequence mono => Data.MonoTraversable.MonoComonad (Data.NonNull.NonNull mono)
-- | Warning: This module should be considered highly experimental.
module Data.Containers
-- | A container whose values are stored in Key-Value pairs.
class (Monoid set, Semigroup set, MonoFoldable set, Eq (ContainerKey set), GrowingAppend set) => SetContainer set where type ContainerKey set unions = ofoldl' union mempty where {
type family ContainerKey set;
}
-- | Check if there is a value with the supplied key in the container.
member :: SetContainer set => ContainerKey set -> set -> Bool
-- | Check if there isn't a value with the supplied key in the container.
notMember :: SetContainer set => ContainerKey set -> set -> Bool
-- | Get the union of two containers.
union :: SetContainer set => set -> set -> set
-- | Combine a collection of <tt>SetContainer</tt>s, with left-most values
-- overriding when there are matching keys.
unions :: (SetContainer set, MonoFoldable mono, Element mono ~ set) => mono -> set
-- | Get the difference of two containers.
difference :: SetContainer set => set -> set -> set
-- | Get the intersection of two containers.
intersection :: SetContainer set => set -> set -> set
-- | Get a list of all of the keys in the container.
keys :: SetContainer set => set -> [ContainerKey set]
-- | This instance uses the functions from <a>Data.Map.Strict</a>.
-- | This instance uses the functions from <a>Data.HashMap.Strict</a>.
-- | This instance uses the functions from <a>Data.IntMap.Strict</a>.
-- | A guaranteed-polymorphic <tt>Map</tt>, which allows for more
-- polymorphic versions of functions.
class PolyMap map
-- | Get the difference between two maps, using the left map's values.
differenceMap :: PolyMap map => map value1 -> map value2 -> map value1
-- | Get the intersection of two maps, using the left map's values.
intersectionMap :: PolyMap map => map value1 -> map value2 -> map value1
-- | Get the intersection of two maps with a supplied function that takes
-- in the left map's value and the right map's value.
intersectionWithMap :: PolyMap map => (value1 -> value2 -> value3) -> map value1 -> map value2 -> map value3
-- | This instance uses the functions from <a>Data.Map.Strict</a>.
-- | This instance uses the functions from <a>Data.HashMap.Strict</a>.
-- | This instance uses the functions from <a>Data.IntMap.Strict</a>.
-- | A <tt>Map</tt> type polymorphic in both its key and value.
class BiPolyMap map where type BPMKeyConstraint map key :: Constraint where {
type family BPMKeyConstraint map key :: Constraint;
}
mapKeysWith :: (BiPolyMap map, BPMKeyConstraint map k1, BPMKeyConstraint map k2) => (v -> v -> v) -> (k1 -> k2) -> map k1 v -> map k2 v
-- | Polymorphic typeclass for interacting with different map types
class (MonoTraversable map, SetContainer map) => IsMap map where type MapValue map findWithDefault def key = fromMaybe def . lookup key insertWith f k v m = v' `seq` insertMap k v' m where v' = case lookup k m of { Nothing -> v Just vold -> f v vold } insertWithKey f k v m = v' `seq` insertMap k v' m where v' = case lookup k m of { Nothing -> v Just vold -> f k v vold } insertLookupWithKey f k v m = v' `seq` (mold, insertMap k v' m) where (mold, v') = case lookup k m of { Nothing -> (Nothing, v) Just vold -> (Just vold, f k v vold) } adjustMap f k m = case lookup k m of { Nothing -> m Just v -> let v' = f v in v' `seq` insertMap k v' m } adjustWithKey f k m = case lookup k m of { Nothing -> m Just v -> let v' = f k v in v' `seq` insertMap k v' m } updateMap f k m = case lookup k m of { Nothing -> m Just v -> case f v of { Nothing -> deleteMap k m Just v' -> v' `seq` insertMap k v' m } } updateWithKey f k m = case lookup k m of { Nothing -> m Just v -> case f k v of { Nothing -> deleteMap k m Just v' -> v' `seq` insertMap k v' m } } updateLookupWithKey f k m = case lookup k m of { Nothing -> (Nothing, m) Just v -> case f k v of { Nothing -> (Just v, deleteMap k m) Just v' -> v' `seq` (Just v', insertMap k v' m) } } alterMap f k m = case f mold of { Nothing -> case mold of { Nothing -> m Just _ -> deleteMap k m } Just v -> insertMap k v m } where mold = lookup k m unionWith f x y = mapFromList $ loop $ mapToList x ++ mapToList y where loop [] = [] loop ((k, v) : rest) = case lookup k rest of { Nothing -> (k, v) : loop rest Just v' -> (k, f v v') : loop (deleteMap k rest) } unionWithKey f x y = mapFromList $ loop $ mapToList x ++ mapToList y where loop [] = [] loop ((k, v) : rest) = case lookup k rest of { Nothing -> (k, v) : loop rest Just v' -> (k, f k v v') : loop (deleteMap k rest) } unionsWith _ [] = mempty unionsWith _ [x] = x unionsWith f (x : y : z) = unionsWith f (unionWith f x y : z) mapWithKey f = mapFromList . map go . mapToList where go (k, v) = (k, f k v) omapKeysWith g f = mapFromList . unionsWith g . map go . mapToList where go (k, v) = [(f k, v)] where {
type family MapValue map;
}
-- | Look up a value in a map with a specified key.
lookup :: IsMap map => ContainerKey map -> map -> Maybe (MapValue map)
-- | Insert a key-value pair into a map.
insertMap :: IsMap map => ContainerKey map -> MapValue map -> map -> map
-- | Delete a key-value pair of a map using a specified key.
deleteMap :: IsMap map => ContainerKey map -> map -> map
-- | Create a map from a single key-value pair.
singletonMap :: IsMap map => ContainerKey map -> MapValue map -> map
-- | Convert a list of key-value pairs to a map
mapFromList :: IsMap map => [(ContainerKey map, MapValue map)] -> map
-- | Convert a map to a list of key-value pairs.
mapToList :: IsMap map => map -> [(ContainerKey map, MapValue map)]
-- | Like <a>lookup</a>, but uses a default value when the key does not
-- exist in the map.
findWithDefault :: IsMap map => MapValue map -> ContainerKey map -> map -> MapValue map
-- | Insert a key-value pair into a map.
--
-- Inserts the value directly if the key does not exist in the map.
-- Otherwise, apply a supplied function that accepts the new value and
-- the previous value and insert that result into the map.
insertWith :: IsMap map => (MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> map
-- | Insert a key-value pair into a map.
--
-- Inserts the value directly if the key does not exist in the map.
-- Otherwise, apply a supplied function that accepts the key, the new
-- value, and the previous value and insert that result into the map.
insertWithKey :: IsMap map => (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> map
-- | Insert a key-value pair into a map, return the previous key's value if
-- it existed.
--
-- Inserts the value directly if the key does not exist in the map.
-- Otherwise, apply a supplied function that accepts the key, the new
-- value, and the previous value and insert that result into the map.
insertLookupWithKey :: IsMap map => (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> ContainerKey map -> MapValue map -> map -> (Maybe (MapValue map), map)
-- | Apply a function to the value of a given key.
--
-- Returns the input map when the key-value pair does not exist.
adjustMap :: IsMap map => (MapValue map -> MapValue map) -> ContainerKey map -> map -> map
-- | Equivalent to <a>adjustMap</a>, but the function accepts the key, as
-- well as the previous value.
adjustWithKey :: IsMap map => (ContainerKey map -> MapValue map -> MapValue map) -> ContainerKey map -> map -> map
-- | Apply a function to the value of a given key.
--
-- If the function returns <a>Nothing</a>, this deletes the key-value
-- pair.
--
-- Returns the input map when the key-value pair does not exist.
updateMap :: IsMap map => (MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
-- | Equivalent to <a>updateMap</a>, but the function accepts the key, as
-- well as the previous value.
updateWithKey :: IsMap map => (ContainerKey map -> MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
-- | Apply a function to the value of a given key.
--
-- If the map does not contain the key this returns <a>Nothing</a> and
-- the input map.
--
-- If the map does contain the key but the function returns
-- <a>Nothing</a>, this returns the previous value and the map with the
-- key-value pair removed.
--
-- If the map contains the key and the function returns a value, this
-- returns the new value and the map with the key-value pair with the new
-- value.
updateLookupWithKey :: IsMap map => (ContainerKey map -> MapValue map -> Maybe (MapValue map)) -> ContainerKey map -> map -> (Maybe (MapValue map), map)
-- | Update/Delete the value of a given key.
--
-- Applies a function to previous value of a given key, if it results in
-- <a>Nothing</a> delete the key-value pair from the map, otherwise
-- replace the previous value with the new value.
alterMap :: IsMap map => (Maybe (MapValue map) -> Maybe (MapValue map)) -> ContainerKey map -> map -> map
-- | Combine two maps.
--
-- When a key exists in both maps, apply a function to both of the values
-- and use the result of that as the value of the key in the resulting
-- map.
unionWith :: IsMap map => (MapValue map -> MapValue map -> MapValue map) -> map -> map -> map
unionWithKey :: IsMap map => (ContainerKey map -> MapValue map -> MapValue map -> MapValue map) -> map -> map -> map
-- | Combine a list of maps.
--
-- When a key exists in two different maps, apply a function to both of
-- the values and use the result of that as the value of the key in the
-- resulting map.
unionsWith :: IsMap map => (MapValue map -> MapValue map -> MapValue map) -> [map] -> map
-- | Apply a function over every key-value pair of a map.
mapWithKey :: IsMap map => (ContainerKey map -> MapValue map -> MapValue map) -> map -> map
-- | Apply a function over every key of a pair and run <a>unionsWith</a>
-- over the results.
omapKeysWith :: IsMap map => (MapValue map -> MapValue map -> MapValue map) -> (ContainerKey map -> ContainerKey map) -> map -> map
-- | This instance uses the functions from <a>Data.Map.Strict</a>.
-- | This instance uses the functions from <a>Data.HashMap.Strict</a>.
-- | This instance uses the functions from <a>Data.IntMap.Strict</a>.
-- | Polymorphic typeclass for interacting with different set types
class (SetContainer set, Element set ~ ContainerKey set) => IsSet set
-- | Insert a value into a set.
insertSet :: IsSet set => Element set -> set -> set
-- | Delete a value from a set.
deleteSet :: IsSet set => Element set -> set -> set
-- | Create a set from a single element.
singletonSet :: IsSet set => Element set -> set
-- | Convert a list to a set.
setFromList :: IsSet set => [Element set] -> set
-- | Convert a set to a list.
setToList :: IsSet set => set -> [Element set]
-- | Zip operations on <a>MonoFunctor</a>s.
class MonoFunctor mono => MonoZip mono
-- | Combine each element of two <a>MonoZip</a>s using a supplied function.
ozipWith :: MonoZip mono => (Element mono -> Element mono -> Element mono) -> mono -> mono -> mono
-- | Take two <a>MonoZip</a>s and return a list of the pairs of their
-- elements.
ozip :: MonoZip mono => mono -> mono -> [(Element mono, Element mono)]
-- | Take a list of pairs of elements and return a <a>MonoZip</a> of the
-- first components and a <a>MonoZip</a> of the second components.
ounzip :: MonoZip mono => [(Element mono, Element mono)] -> (mono, mono)
-- | Type class for maps whose keys can be converted into sets.
class SetContainer set => HasKeysSet set where type KeySet set where {
type family KeySet set;
}
-- | Convert a map into a set of its keys.
keysSet :: HasKeysSet set => set -> KeySet set
instance GHC.Classes.Ord k => Data.Containers.SetContainer (Data.Map.Base.Map k v)
instance (GHC.Classes.Eq key, Data.Hashable.Class.Hashable key) => Data.Containers.SetContainer (Data.HashMap.Base.HashMap key value)
instance Data.Containers.SetContainer (Data.IntMap.Base.IntMap value)
instance GHC.Classes.Ord element => Data.Containers.SetContainer (Data.Set.Base.Set element)
instance (GHC.Classes.Eq element, Data.Hashable.Class.Hashable element) => Data.Containers.SetContainer (Data.HashSet.HashSet element)
instance Data.Containers.SetContainer Data.IntSet.Base.IntSet
instance GHC.Classes.Eq key => Data.Containers.SetContainer [(key, value)]
instance GHC.Classes.Ord key => Data.Containers.PolyMap (Data.Map.Base.Map key)
instance (GHC.Classes.Eq key, Data.Hashable.Class.Hashable key) => Data.Containers.PolyMap (Data.HashMap.Base.HashMap key)
instance Data.Containers.PolyMap Data.IntMap.Base.IntMap
instance Data.Containers.BiPolyMap Data.Map.Base.Map
instance Data.Containers.BiPolyMap Data.HashMap.Base.HashMap
instance GHC.Classes.Ord key => Data.Containers.IsMap (Data.Map.Base.Map key value)
instance (GHC.Classes.Eq key, Data.Hashable.Class.Hashable key) => Data.Containers.IsMap (Data.HashMap.Base.HashMap key value)
instance Data.Containers.IsMap (Data.IntMap.Base.IntMap value)
instance GHC.Classes.Eq key => Data.Containers.IsMap [(key, value)]
instance GHC.Classes.Ord element => Data.Containers.IsSet (Data.Set.Base.Set element)
instance (GHC.Classes.Eq element, Data.Hashable.Class.Hashable element) => Data.Containers.IsSet (Data.HashSet.HashSet element)
instance Data.Containers.IsSet Data.IntSet.Base.IntSet
instance Data.Containers.MonoZip Data.ByteString.Internal.ByteString
instance Data.Containers.MonoZip Data.ByteString.Lazy.Internal.ByteString
instance Data.Containers.MonoZip Data.Text.Internal.Text
instance Data.Containers.MonoZip Data.Text.Internal.Lazy.Text
instance GHC.Classes.Ord k => Data.Containers.HasKeysSet (Data.Map.Base.Map k v)
instance Data.Containers.HasKeysSet (Data.IntMap.Base.IntMap v)
instance (Data.Hashable.Class.Hashable k, GHC.Classes.Eq k) => Data.Containers.HasKeysSet (Data.HashMap.Base.HashMap k v)
|