{"id":16965040,"url":"https://github.com/propensive/chiaroscuro","last_synced_at":"2025-08-19T10:32:47.713Z","repository":{"id":80754909,"uuid":"595056123","full_name":"propensive/chiaroscuro","owner":"propensive","description":"Provides structural comparisons between values","archived":false,"fork":false,"pushed_at":"2024-12-14T14:26:10.000Z","size":1056,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-14T15:24:51.459Z","etag":null,"topics":["deep-compare","deep-compare-objects","scala","structural-equality"],"latest_commit_sha":null,"homepage":"","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":"2023-01-30T09:55:16.000Z","updated_at":"2024-12-14T14:26:14.000Z","dependencies_parsed_at":"2023-12-07T09:35:17.844Z","dependency_job_id":"237ec77b-9b6a-4fb4-9166-09ab7d90537b","html_url":"https://github.com/propensive/chiaroscuro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fchiaroscuro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fchiaroscuro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fchiaroscuro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fchiaroscuro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/chiaroscuro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230347045,"owners_count":18212188,"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":["deep-compare","deep-compare-objects","scala","structural-equality"],"created_at":"2024-10-13T23:44:53.318Z","updated_at":"2025-08-19T10:32:47.695Z","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/chiaroscuro/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/chiaroscuro/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# Chiaroscuro\n\n__Compare and contrast similar objects and highlight their differences__\n\nA simple equality test can determine whether two values are identical or not,\nbut it offers no explanation for _how_ two unequal values are different.\n_Chiaroscuro_ provides a means to compare two objects and see their structural\ndifferences.\n\n## Features\n\n- structurally compare different values of the same type\n- provides a recursive structural breakdown of differences between product types\n- provides a diff (using Myers' algorithm) between sequence types with different elements\n- presents results as an immutable datatype which can be rendered as a tabular tree of differences\n- diff sequences can be customized for more meaningful output\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\nAll Chiaroscuro terms and types are defined in the `chiaroscuro` package:\n```scala\nimport chiaroscuro.*\n```\n\nTwo values of the same type can be compared with the `contrastWith` method,\nprovided by Chiaroscuro. This will return an instance of `Semblance`,\ndescribing the similarity of one value with the other, and will be one of three\ncases:\n- `Identical`, if the two values are the same\n- `Different`, if the two values are different, without any further detail\n- `Breakdown`, if the two values are different, with a breakdown of their\n  similarities and differences\n\nThe last of these three cases is the most interesting, though it is only a\npossible result for values of certain types, namely types which can be\ndestructured into components which can themselves be compared, recursively.\nSimple types like `Text` (or `String`) and primitive types like `Int` or\n`Double` can only ever be `Identical` or `Different`, but product types, like\ncase class instances, sum types, like enums or sealed traits, and sequence\ntypes, like `List` or `IArray` can result in semblances which are neither\n`Identical` nor `Different` but a `Breakdown`.\n\nThe three cases of `Semblance` are defined as follows:\n- `Identical(value: Text)`\n- `Different(left: Text, right: Text)`\n- `Breakdown(comparison: IArray[(Text, Semblance)], left: Text, right: Text)`\n\n`Identical` includes just a textual representation of the two identical values.\n`Different` includes textual representations of _both_ values, since they will\nnot be the same. `Breakdown` also includes textual representations of the left\nand right values, but additionally includes a sequence (an `IArray`) of\nlabelled `Semblance`s, each of which may be `Identical`, `Different` or another\n`Breakdown`. This sequence represents a breakdown of the different components of\nthe two objects, comparing like-for-like, however the breakdown depends on the\ntype of objects being contrasted.\n\nTypically, for product types such as case classes, the comparison sequence will\ncontain an entry for each parameter of the case class, showing whether that\nparameter is the same or differs between the two values. In the case where it\ndiffers, and the parameter is another product type, a nested `Breakdown` instance\nmay recursively show \n\nFor sequence types, such as `List`, a diff between the elements of the left\nsequence and the elements of the right sequence will yield a comparison\nsequence, labeled for the index of the left and/or right sequence, where each\nentry represents a one-to-one comparison between two elements, an addition (to\nthe right side) or a deletion (from the left side). Each one-to-one comparison\nmay be `Identical`, `Different` or a recursive `Breakdown` value.\n\nThis format provides a convenient and concise way of describing the structural\ndifferences between two values. A contrast between two deep structures with few\ndifferences will yield a tree structure where identical branches are pruned,\nand only differing branches are expanded.\n\n### _Similar_ elements\n\nWhen performing a diff between two sequences of elements, whatever their type,\na comparison between any two elements will judge them to be either the same or\ndifferent, however small the difference. The non-appearance of an element in\none sequence and its appearance in the other would be considered a deletion or\ninsertion. In general, the result of a diff could be presented as an\nalternating series of blocks of identical elements and blocks of deletions\n(from the left side) and insertions (on the right side).\n\nOften this is the best that can be achieved, and Chiaroscuro would present each\ndeletion and insertion as `Different` nodes: absent on one side, and present on\nthe other, with no further breakdown possible.\n\nBut what if further analysis on the blocks of differences (those between the\nblocks of identical elements) were possible, and elements appearing on both\nsides deemed _similar_ could be compared to each other? With a definition for\nwhat it means for two elements to be _similar_ (for a given element type)\nChiaroscuro makes this possible, and provides a breakdown of the differences\nbetween similar elements.\n\nFor example, consider the board members of an imaginary company,\n```scala\nimport anticipation.Text\nimport gossamer.t\n\nenum Role:\n  case Ceo, Cto, Coo, Cmo, Cfo\n\ncase class Member(role: Role, name: Text)\n\nval boardMembers: List[Member] = List(\n  Member(Role.Ceo, t\"Jane\"),\n  Member(Role.Cto, t\"Leopold\"),\n  Member(Role.Coo, t\"Simon\"),\n  Member(Role.Cmo, t\"Helen\")\n)\n```\nbeing compared to the board members a year later:\n```scala\nval boardMembers2: List[Member] = List(\n  Member(Role.Ceo, t\"Leopold\"),\n  Member(Role.Cto, t\"Linda\"),\n  Member(Role.Coo, t\"Simon\"),\n  Member(Role.Cfo, t\"Anna\"),\n  Member(Role.Cmo, t\"Helen\")\n)\n```\n\nA simplistic diff would identify that the COO (Simon) and CMO (Helen) remained\nunchanged, and two _sets_ of changes:\n - deletion of Jane (CEO), deletion of Leopold (CTO), insertion of Leopold\n   (CEO) and insertion of Linda (CTO), and\n - insertion of Anna (CFO)\n\nHowever, the first set of changes could be presented more simply if we were to\nprovide an indication of _similarity_ between two `Member` instances. Two\npossibilities suggest themselves:\n 1. two `Member`s with the same name are similar (regardless of role)\n 2. two `Member`s with the same role are similar (regardless of name)\n\nThe presence of a `Similarity` typeclass instance can be used to specify this similarity. Defining,\n```scala\ngiven Similarity[Member] = _.role == _.role\n```\n```\nwill transform the `Semblance` output  comparing these two sequences to\ndirectly compare `Member(Role.Ceo, t\"Jane\")` and\n`Member(Role.Ceo, t\"Leopold\")`, resulting in a `Breakdown` indicating\nthe name having changed, and a similar name change for the corresponding\nmembers with the `Role.Cto` role.\n\nThe insertion of a `Member` with the `Role.Cfo` role would remain as an\ninsertion.\n\nLikewise, providing the alternative `given` definition,\n```scala\ngiven Similarity[Member] = _.name == _.name\n```\nwould show Jane as a deletion, Leopold as a role change from CTO to CEO, and\nLinda and Anna as insertions.\n\nThe implementation of `Similarity` can be any function comparing two elements,\nand a good implementation can dramatically improve the readability of the\n`Semblance` output. Some ideas for similarity implementations include considering:\n- `Text` elements with a minimum edit distance less than 4 to be similar\n- `Double` elements which differ by less than 5% to be similar\n- `Json` objects with equal `\"id\"` fields to be similar\n- a choice the same case of an enum (regardless of parameters) to indicate similarity\n\n\n\n\n\n\n## Status\n\nChiaroscuro is classified as __maturescent__. 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\nChiaroscuro is designed to be _small_. Its entire source code currently consists\nof 192 lines of code.\n\n## Building\n\nChiaroscuro 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 Chiaroscuro?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Chiaroscuro'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 Chiaroscuro 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 `chiaroscuro`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Chiaroscuro'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 Chiaroscuro are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/chiaroscuro/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Chiaroscuro\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\nChiaroscuro 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\n_Chiaroscuro_ is a Renaissance painting technique of expressing strong contrasts between light and dark, while Chiaroscuro provides the means to highlight the contrasts between two values.\n\n### Pronunciation\n\n`/kɪˌɑːɹəˈskʊəɹəʊ/`\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 a stylized crescent moon, illustrating the contrast of light against darkness.\n\n## License\n\nChiaroscuro 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%2Fchiaroscuro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fchiaroscuro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fchiaroscuro/lists"}