package rich-string

All checked builds pass
  1. Overview
  2. Docs
The rich-string library provides a generic way to enrich the built-in string type with new capabilities

Install

dune-project
 Dependency

Authors

Maintainers

Sources

rich-string-1.0.0.tbz
sha256=f376e4ffc99b2991813919dc36fe3f8ac86cc48e64b062151dd97da1ae7153a0
sha512=e5b5512cada9529a4f2415b8112a533204c83ea7ca69a4bd89201c9af04cefc0b009e7f9c4e48e00a06dfcf0dd1c62048555e452766e1bad712751da46809b69

Description

rich-string provides a generic way to enrich the built-in string type with new capabilities.

Tags

string rich rich string formatting

Added to opam-repository:

README

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:

  • Empty
  • String (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, rs2 and rs3, (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-string

Made with 🩷 by lexa. Support me on Ko-fi. Find me on Bluesky.

rich-string's development does not involve any large language model.

rich-string is entirely brain-made.

Dependencies (2)

  1. ocaml >= "5.1"
  2. dune >= "3.20"

Dev Dependencies (2)

  1. odoc with-doc
  2. ppx_expect with-test

Optional Dependencies

None

Used by (1)

  1. ansifmt >= "2.0.0"

Conflicts

None

Build status

Results of building rich-string with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
1.0.0 (this version) n/a n/a good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure