{"id":15994046,"url":"https://github.com/knutwalker/validation","last_synced_at":"2025-04-05T00:15:36.229Z","repository":{"id":31563718,"uuid":"35128447","full_name":"knutwalker/validation","owner":"knutwalker","description":null,"archived":false,"fork":false,"pushed_at":"2017-10-09T12:42:23.000Z","size":1600,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T13:26:00.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://knutwalker.github.io/validation/","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/knutwalker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-05T23:12:02.000Z","updated_at":"2017-10-09T12:28:06.000Z","dependencies_parsed_at":"2022-07-24T17:17:10.017Z","dependency_job_id":null,"html_url":"https://github.com/knutwalker/validation","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knutwalker%2Fvalidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knutwalker%2Fvalidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knutwalker%2Fvalidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knutwalker%2Fvalidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knutwalker","download_url":"https://codeload.github.com/knutwalker/validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266570,"owners_count":20910837,"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":[],"created_at":"2024-10-08T07:05:24.963Z","updated_at":"2025-04-05T00:15:36.200Z","avatar_url":"https://github.com/knutwalker.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Travis CI](https://img.shields.io/travis/knutwalker/validation/master.svg)](https://travis-ci.org/knutwalker/validation)\n[![Coverage Status](https://img.shields.io/codecov/c/github/knutwalker/validation/master.svg)](https://codecov.io/github/knutwalker/validation)\n[![Maven](https://img.shields.io/maven-central/v/de.knutwalker/validation_2.11.svg)](http://search.maven.org/#search|ga|1|g%3A%22de.knutwalker%22%20AND%20a%3A%22validation_2.11%22)\n[![Apache License](https://img.shields.io/badge/license-APACHE_2-green.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n## Validation\n\nA standalone Validation data type, called `Result`. (see [How do I error handle thee?](http://typelevel.org/blog/2014/02/21/error-handling.html) for more on the general idea of a Validation)\n\nThe `Result` type is very similar to `scalaz.Validation`, `cats.data.Validated`, or `org.scalactic.Or` with the following differences:\n\n- no dependencies besides scala and no additional baggage\n\nthat is no Monads, Applicative Functors, Arrows, or Categories.\nThe only thing that is provided besides `Result` is a `NonEmptyVector` which is\nsimilar to a regular `Vector`, only that there will always be at least one element in it.\n\nThe main incentive is, that `Result` can be used in places where a full-fledged\ndependency on `scalaz` and co. is undesired, e.g. in projects with many people\nthat are unfamiliar with or intimidated by `scalaz`.\n\n- explicit symbolic and unsafe operators\n\nBy default, all operations are safe, meaning they are referentially transparent if their input is.\nUnsafe operations (`foreach`, `get`) can be enabled by\nimporting `validation.Result.unsafe._`\n\nAll methods are named aptly (or so I hope) and with ascii characters.\nSymbolic names (such as `|` for `getOrElse` or `|@|` for `and`) can be enabled by\nimporting `validation.Result.symbolic._`\n\n- implied underlying Vector to accumulate data\n\nScalaz differentiates between `Validation[E, A]` and `type ValidationNel[E, A] = Validation[NonEmptyList[E], A]`\nwhere as `Result[E, A]` has an implied `NonEmptyVector` accumulating the `E`.\nIt behaves mostly as a permanent (imaginary) `ResultNev[E, A]`.\n\n### What Validation is not\n\nThis library is not an implementation of a validation framework, just\na general data structure.\n\n\n## Installing\n\n```\n// scala 2.11.x\nlibraryDependencies += \"de.knutwalker\" %% \"validation\" % \"0.2.0\"\n\n// scala 2.12.x\nlibraryDependencies += \"de.knutwalker\" %% \"validation\" % \"0.3.0\"\n```\n\n\n## Usage\n\n```scala\nimport validation._\n\ntype Validated[A] = Result[String, A]\n\ncase class Person(name: String, age: Int)\n\ndef parseName(s: String): Validated[String] =\n  if (s.trim.nonEmpty) Result.valid(s.trim)\n  else Result.invalid(s\"invalid name: '$s'\")\n\ndef parseAge(s: String): Validated[Int] =\n  Result.catching[NumberFormatException]\n    .using(_.getMessage)\n    .run(s.trim.toInt)\n    .filter(_ \u003e= 0, s\"invalid age: '$s'\")\n\ndef parsePerson(name: String, age: String): Validated[Person] =\n   (parseName(name) and parseAge(age)) apply Person\n\nparsePerson(\"Bernd\", \"42\")\n// res0: Validated[Person] = Valid(Person(Bernd,42))\n\nparsePerson(\"Bernd\", \"fortytwo\")\n// res1: Validated[Person] = Invalid(For input string: \"fortytwo\")\n\nparsePerson(\"Bernd\", \"-1337\")\n// res2: Validated[Person] = Invalid(invalid age: '-1337')\n\nparsePerson(\"\", \"\")\n// res3: Validated[Person] = Invalids(NonEmptyVector(invalid name: '',For input string: \"\"))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknutwalker%2Fvalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknutwalker%2Fvalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknutwalker%2Fvalidation/lists"}