Page
Library
Module
Module type
Parameter
Class
Class type
Source
rich-string provides a generic way to enrich the built-in string type with new capabilities.
The resulting rich string type is powerful: simple, composable, optimizing and extensible.
The type is made of four straightforward variants:
EmptyString (built-in string)Enriched (enrichment, rich string)Join (separator, rich strings)Just like the built-in string, rich strings form a monoid.
rs, empty ++ rs = rs ++ empty = rs.rs1, rs2 and rs3, (rs1 ++ rs2) ++ rs3 = rs1 ++ (rs2 ++ rs3).Rich strings are carefully crafted for common cases. Operations on rich strings avoid unnecessary structural deep-nesting when possible.
empty ++ rs = rs ++ empty = rs.join ~on:sep rss1 ++ join ~on:sep rss2 = join ~on:sep (rss1 @ rss2).rs ++ join ~on:empty rss = join ~on:empty (rs :: rss).enrich e rs1 ++ enrich e rs2 = enrich e (rs1 ++ rs2).With a mostly transparent interface, rich strings can be extended to fulfill specific needs.
For example:
As a library, rich-string is tested from the ground-up, with a focus on checking that its advertised properties hold.
Add rich-string to your dune-project, in the depends section:
(package
(name your-package)
(depends
...
(rich-string (>= 1.0))))rich-string is available on the OPAM index.
opam install rich-stringMade with 🩷 by lexa. Support me on Ko-fi. Find me on Bluesky.
rich-string's development does not involve any large language model.