{"id":15966823,"url":"https://github.com/davidgregory084/robots","last_synced_at":"2025-04-04T13:27:15.652Z","repository":{"id":57732941,"uuid":"97071951","full_name":"DavidGregory084/robots","owner":"DavidGregory084","description":"A helper library for validating data with Cats","archived":false,"fork":false,"pushed_at":"2018-07-09T12:44:43.000Z","size":1705,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T23:17:14.415Z","etag":null,"topics":["cats","functional-programming","scala","validation"],"latest_commit_sha":null,"homepage":"https://davidgregory084.github.io/robots/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DavidGregory084.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-13T02:34:22.000Z","updated_at":"2019-01-08T12:58:56.000Z","dependencies_parsed_at":"2022-09-26T22:11:11.985Z","dependency_job_id":null,"html_url":"https://github.com/DavidGregory084/robots","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/DavidGregory084%2Frobots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidGregory084%2Frobots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidGregory084%2Frobots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidGregory084%2Frobots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidGregory084","download_url":"https://codeload.github.com/DavidGregory084/robots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247184118,"owners_count":20897717,"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":["cats","functional-programming","scala","validation"],"created_at":"2024-10-07T18:05:08.758Z","updated_at":"2025-04-04T13:27:15.635Z","avatar_url":"https://github.com/DavidGregory084.png","language":"Scala","readme":"## Robots\n\n[![Build Status](https://api.travis-ci.org/DavidGregory084/robots.svg)](https://travis-ci.org/DavidGregory084/robots)\n[![Coverage Status](http://codecov.io/github/DavidGregory084/robots/coverage.svg?branch=master)](http://codecov.io/github/DavidGregory084/robots?branch=master)\n[![License](https://img.shields.io/github/license/DavidGregory084/robots.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Latest Version](https://img.shields.io/maven-central/v/io.github.davidgregory084/robots-core_2.12.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.davidgregory084%22%20AND%20a%3A%22robots-core_2.12%22)\n\n### Overview\n\nRobots is a small Scala library which aims to provide helpful utilities for validating data using the type classes and data types provided by the [Cats](https://github.com/typelevel/cats) library.\n\n### Getting Started\n\nAdd the following to your `build.sbt`:\n\n```scala\nlibraryDependencies += \"io.github.davidgregory084\" %% \"robots\" % \"0.1.0\"\n```\n\n### Example\n\n```scala\nimport robots.Validator, Validator._\nimport cats.data.Validated\nimport cats.instances.either._\nimport cats.instances.list._\nimport cats.instances.int._\n\ncase class Document(maxColumn: Int, maxLines: Int, lines: List[String])\n\nval passing = Document(80, 120, List(\"Hello\", \"World\"))\nval failing = Document(4, 1, List(\"Hey\", \"World\"))\n\nval documentValidator =\n  validate[List, String, Document].\n    has(_.maxColumn)(gt(0, List(\"Max width should be greater than zero\"))).\n    has(_.maxLines)(gt(0, List(\"Max line count should be greater than zero\"))).\n    has2(_.maxLines, _.lines)(Validator {\n      case (maxLines, lines) =\u003e\n        if (lines.length \u003c= maxLines)\n          Nil\n        else\n          List(\"Exceeded the maximum number of lines\")\n    }).\n    all2(_.maxColumn, _.lines)(Validator {\n      case (maxColumn, line) =\u003e\n        if (line.length \u003c= maxColumn)\n          Nil\n        else\n          List(\"Exceeded the maximum number of columns\")\n    })\n```\n\n```scala\n// Works well with `Either` and `Validated`\ndocumentValidator.runNel[Validated](passing)\n// res4: cats.data.Validated[cats.data.NonEmptyList[String],Document] = Valid(Document(80,120,List(Hello, World)))\n\ndocumentValidator.runNel[Validated](failing)\n// res5: cats.data.Validated[cats.data.NonEmptyList[String],Document] = Invalid(NonEmptyList(Exceeded the maximum number of lines, Exceeded the maximum number of columns))\n\ndocumentValidator.runNel[Either](passing)\n// res6: Either[cats.data.NonEmptyList[String],Document] = Right(Document(80,120,List(Hello, World)))\n\ndocumentValidator.runNel[Either](failing)\n// res7: Either[cats.data.NonEmptyList[String],Document] = Left(NonEmptyList(Exceeded the maximum number of lines, Exceeded the maximum number of columns))\n\n// You can brjng any `MonadError`\nimport cats.data.Ior\n// import cats.data.Ior\n\ndocumentValidator.run[Ior[List[String], ?]](passing)\n// res9: cats.data.Ior[List[String],Document] = Right(Document(80,120,List(Hello, World)))\n\ndocumentValidator.run[Ior[List[String], ?]](failing)\n// res10: cats.data.Ior[List[String],Document] = Left(List(Exceeded the maximum number of lines, Exceeded the maximum number of columns))\n\n// Even ones that discard errors\nimport cats.instances.option._\n// import cats.instances.option._\n\ndocumentValidator.run_[Option](passing)\n// res12: Option[Document] = Some(Document(80,120,List(Hello, World)))\n\ndocumentValidator.run_[Option](failing)\n// res13: Option[Document] = None\n```\n\n### Conduct\n\nContributors are expected to follow the [Typelevel Code of Conduct](http://typelevel.org/conduct.html) while participating on Github and any other venues associated with the project. \n\n### Acknowledgements\n\nThanks to Dave Gurnell ([@davegurnell](https://github.com/davegurnell)) and Brendan Maginnis ([@brendanator](https://github.com/brendanator)) for the design which inspired this library.\n\n### License\n\nAll code in this repository is licensed under the Apache License, Version 2.0.  See [LICENSE](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidgregory084%2Frobots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidgregory084%2Frobots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidgregory084%2Frobots/lists"}