package rich-string
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f376e4ffc99b2991813919dc36fe3f8ac86cc48e64b062151dd97da1ae7153a0
sha512=e5b5512cada9529a4f2415b8112a533204c83ea7ca69a4bd89201c9af04cefc0b009e7f9c4e48e00a06dfcf0dd1c62048555e452766e1bad712751da46809b69
doc/README.html
Rich String
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.
Simple
The type is made of four straightforward variants:
EmptyString (built-in string)Enriched (enrichment, rich string)Join (separator, rich strings)
Composable
Just like the built-in string, rich strings form a monoid.
- Identity: for all rich strings
rs,empty ++ rs = rs ++ empty = rs. - Associativity: for all rich strings
rs1,rs2andrs3,(rs1 ++ rs2) ++ rs3 = rs1 ++ (rs2 ++ rs3).
Optimizing
Rich strings are carefully crafted for common cases. Operations on rich strings avoid unnecessary structural deep-nesting when possible.
- Identity:
empty ++ rs = rs ++ empty = rs. - Inner concatenation:
join ~on:sep rss1 ++ join ~on:sep rss2 = join ~on:sep (rss1 @ rss2). - Inner consing:
rs ++ join ~on:empty rss = join ~on:empty (rs :: rss). - Enrichement grouping:
enrich e rs1 ++ enrich e rs2 = enrich e (rs1 ++ rs2).
Extensible
With a mostly transparent interface, rich strings can be extended to fulfill specific needs.
For example:
- Indexing
- Labelling
- ANSI formatting
Tested
As a library, rich-string is tested from the ground-up, with a focus on checking that its advertised properties hold.
Convinced?
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.