{"id":16964963,"url":"https://github.com/propensive/gossamer","last_synced_at":"2025-04-11T23:01:44.797Z","repository":{"id":37233454,"uuid":"405930332","full_name":"propensive/gossamer","owner":"propensive","description":"Lightweight and typesafe strings in Scala","archived":false,"fork":false,"pushed_at":"2025-02-11T21:31:00.000Z","size":5854,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-06T07:46:35.157Z","etag":null,"topics":["encodings","minimum-edit-distance","opaque-type","punycode","scala","strings","text"],"latest_commit_sha":null,"homepage":"https://soundness.dev/gossamer/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-13T10:37:42.000Z","updated_at":"2025-02-11T21:31:04.000Z","dependencies_parsed_at":"2023-12-08T10:30:20.310Z","dependency_job_id":"5a25ef60-95c9-435a-9bd3-e0f5585dd845","html_url":"https://github.com/propensive/gossamer","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fgossamer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fgossamer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fgossamer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fgossamer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/gossamer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492875,"owners_count":21113162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encodings","minimum-edit-distance","opaque-type","punycode","scala","strings","text"],"created_at":"2024-10-13T23:44:42.301Z","updated_at":"2025-04-11T23:01:44.757Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/gossamer/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/gossamer/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Gossamer\n\n__Lightweight string utilities__\n\nThe Java implementation of `String` provides many methods which are useful, but\nsome lack sufficient typesafety. Gossamer provides the `Text` type, a more\ntypesafe opaque type alias of `String`.\n\n## Features\n\n- reimplements common methods on `String` with more typesafe variants\n- provides an implementation of the Minimum Edit Distance algorithm\n- convenient converters to common encodings like URL encodings and Punycode\n- implements a stricter `t\"\"` interpolator for strings\n- implements the `txt\"\"` interpolator to ignore spurious whitespace in strings which flow onto multiple lines\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\n_Gossamer_ provides a collection of useful methods and constructors for working with strings.\n\nAll Gossamer terms and types are defined in the `gossamer` package:\n```scala\nimport gossamer.*\n```\n\n### `Show` typeclass\n\nA standard `Show` typeclass is provided which will convert values of different types into `String`s.\n\nMany types, such as `Int`s, only have a single reasonable presentation as a `String`, while others,\nfor example instances of case classes, may be presented in different ways depending on the context.\nGossamer's `Show` typeclass does not prescribe exactly where and when it should be used, but\ninstances of `Show` should produce strings which meaningfully present a value as a string, usually\nfor human consumption.\n\nUsing [Wisteria](https://github.com/propensive/wisteria), `Show` instances for product types (such\nas case classes and tuples) and coproduct types (such as enumerations and sealed traits) will be\nautomatically derived.\n\n### `Text`, a typesafe `String`\n\nThe `Text` type in `anticipation` is provided as an opaque alias of `String`,\nduplicating most of the functionality of `String` (and its associated extension\nmethods), but without the typesafety risks associated with `String`. `Text`\ninstances may only be combined with other types when a `Show` typeclass\ninstance exists for that type.\n\nFurthermore, every method of `Text` is guaranteed not to be `null` and declares any exceptions it\nmay throw.\n\n#### Interpolators\n\nScala's standard library provides the `s` interpolator which allows elements of any type to be\nsubstituted into a `String`. This presents a typesafety hole, since `toString` must be applied to\neach one, without any guarantee that it produces a reasonable presentation of that value as a\n`String`.\n\nSo Gossamer introduces the `str\"\"` interpolator which only permits types with a corresponding\n`Show` typeclass instance to be substituted into a string: other types will result in an error.\nThe `toString` method will never be called on these substitutions.\n\n#### Long strings\n\nAdditionally, a `txt\"\"` interpolator is provided for constructing \"long\" strings which need to be\nsplit across several lines of code, but where any whitespace (such as indentation and newlines)\nshould always be read as a single space character, unless it contains two adjacent newlines, in\nwhich case it should be interpreted as a \"new paragraph\", represented as a single newline (`'\\n'`)\ncharacter.\n\nThis is particularly useful for embedding long messages in code while not breaking the consistency\nof indentation. For example:\n```scala\nimport anticipation.Text\n\nval msg: Text = txt\"\"\"This is a long message which will not fit into a\n                      standard line of code, and needs to be split across\n                      several lines.\n\n                      But at least it is aligned nicely within the code.\"\"\"\n```\n\nThe `String` `msg` will contain a single `'\\n'` character, between `lines.` and `But`.\n\n#### `DebugString` typeclass\n\nIn addition to `Show`, Gossamer provides a `DebugString` single-abstract-method typeclass which is\ndesigned to provide `String` representations of values as valid Scala expressions that could be\ncopied and pasted into code.\n\nLike the `Show` typeclass, product and coproduct instances of `DebugString` are automatically\nderived.\n\n### Encodings\n\nSimple extension methods which provide a number of string-based encodings are provided. The\n`urlEncode` and `urlDecode` methods will convert to and from (respectively) strings in the\nURL encoding scheme. The `punycode` method will convert the string (most commonly, a domain name)\ninto a ASCII-only representation of the string, encoding any non-ASCII characters as Punycode.\n\n### Safer `String` methods\n\nSafer alternatives to many of the commonly-used methods of `String` are provided. These typically\ndelegate to existing methods on `String`, but will:\n- never return `null`\n- never return mutable arrays\n- never accept `Any` as a parameter type, or implicitly use `String#toString` to convert\n  non-`String` types to `String`s\n\n### Minimum Edit Distance\n\nAn implementation of the _Minimum Edit Distance_ or [Levenshtein\ndistance](https://en.wikipedia.org/wiki/Levenshtein_distance), `lev` is provided as an extension\nmethod on `Text`s. The method takes another `Text` as a parameter, and returns the minimum\nnumber of edits (character additions, deletions or replacements) required to change one string to\nthe other.\n\nFor example, `t\"Hello\".lev(t\"Hallo!\")` returns `2`: the replacement of `e` with `a` counts as one\nedit, and the addition of `!` counts as the second edit. The algorithm is symmetrical.\n\n### Joining\n\nScala's standard library provides the `mkString` method on collection types, but this unfortunately\ncalls `toString` on every element in the collection, without warning. Gossamer provides a `join`\nmethod which may only be applied to values that are already `String`s.\n\nThis is further generalized with a `Joinable` typeclass: if an instance exists for other\n`String`-like types, they may also be `join`ed like a collection of `String`s, where every\nparameter to `join` is of the same type as the elements of the collection.\n\nIn addition to the zero-, one- and three-parameter variants of `join` which behave like their\n`mkString` equivalents, two- and four-parameter versions are also provided. These allow a different\nseparator to be used between the penultimate and last elements of the collection.\n\nFor example,\n```scala\nval numbers = List(t\"one\", t\"two\", t\"three\", t\"four\").join(t\", \", t\" and \")\n```\nwill evaluate to `\"one, two, three and four\"`, and,\n```scala\nval numbers2 = List(t\"one\", t\"two\", t\"three\").join(t\"Choose \", t\", \", t\" or \", t\".\")\n```\nresults in, `t\"Choose one, two or three.\"`.\n\n\n\n\n\n\n## Status\n\nGossamer is classified as __fledgling__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nGossamer is designed to be _small_. Its entire source code currently consists\nof 1211 lines of code.\n\n## Building\n\nGossamer will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Gossamer?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Gossamer's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Gossamer and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `gossamer`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Gossamer's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Gossamer are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/gossamer/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Gossamer\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nGossamer was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\nGossamer is lightweight and stringlike.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo shows the glowing tip of a gossamer-thin fibreoptic cable.\n\n## License\n\nGossamer is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fgossamer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fgossamer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fgossamer/lists"}