{"id":34602150,"url":"https://github.com/throup/couldbe","last_synced_at":"2026-06-05T07:31:13.059Z","repository":{"id":167009529,"uuid":"642565725","full_name":"throup/couldbe","owner":"throup","description":"couldbe is a Scala library for specifying optional Given instances (previously known as implicits).","archived":false,"fork":false,"pushed_at":"2025-01-30T01:38:09.000Z","size":1561,"stargazers_count":0,"open_issues_count":17,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T04:08:42.447Z","etag":null,"topics":["given","implicit","scala","scala3","types"],"latest_commit_sha":null,"homepage":"https://throup.github.io/couldbe/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/throup.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-18T21:32:50.000Z","updated_at":"2023-05-24T18:21:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"e34b4140-6e76-4761-a73c-26860d0ce067","html_url":"https://github.com/throup/couldbe","commit_stats":null,"previous_names":["throup/couldbe"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/throup/couldbe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/throup%2Fcouldbe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/throup%2Fcouldbe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/throup%2Fcouldbe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/throup%2Fcouldbe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/throup","download_url":"https://codeload.github.com/throup/couldbe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/throup%2Fcouldbe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33934409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["given","implicit","scala","scala3","types"],"created_at":"2025-12-24T12:53:41.467Z","updated_at":"2026-06-05T07:31:13.051Z","avatar_url":"https://github.com/throup.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# couldbe: optional Givens for Scala\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/throup/couldbe/scala.yml)](https://github.com/throup/couldbe/actions/workflows/scala.yml)\n[![couldbe Scala version support](https://index.scala-lang.org/throup/couldbe/couldbe/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/throup/couldbe/couldbe)\n[![codecov](https://codecov.io/gh/throup/couldbe/branch/main/graph/badge.svg?token=XSUAQWYIOO)](https://codecov.io/gh/throup/couldbe)\n[![javadoc](https://javadoc.io/badge2/eu.throup/couldbe-core_3/javadoc.svg)](https://javadoc.io/doc/eu.throup/couldbe-core_3)\n\n![Cats Friendly Badge](https://typelevel.org/cats/img/cats-badge-tiny.png)\n\n## Overview\n\n**couldbe** is a small library, for the [Scala programming language](https://scala-lang.org), allowing you to refer to optional `given` instances (known as implicits in Scala 2).\n\nBecause `given` instances are resolved at compile time, they are either available or they are not. If your code requires a `given` instance, you add it to the function signature; if it doesn't, then you don't.\n\nBut what if your code _could_ use a `given` instance, but doesn't require one?  Maybe you are writing an algorithm which _could_ be simplified with evidence of a Monad, but doesn't actually require it? Or maybe you can provide a sensible default if the `given` value is not defined?\n\nThat's where **couldbe** can help you out.\n\n### Quick example\n(more examples later in the document)\n\n```scala\n// Function to return a Given string, if it is defined; or a default value otherwise.\ndef simpleGivenParameter(using message: CouldBeGiven[String]) =\n  message match\n    case IsGiven(actual) =\u003e actual\n    case IsNotGiven      =\u003e \"This is a default string\"\n\n// ---\n// With no given String, the function returns the default value.\nsimpleGivenParameter == \"This is a default string\"\n\n// ---\n// With a given String, that is the value returned.\ngiven String = \"This string is given\"\nsimpleGivenParameter == \"This string is given\"\n```\n\nPlease note: it's not usually good practice to pass around something as generic as a `String` type in a `given` instance. This is a simple example to demonstrate the functionality.\n\n## Getting started\nTo include **couldbe** in your project, add the appropriate dependencies to your `build.sbt`:\n```sbt\nlibraryDependencies += \"eu.throup\" %% \"couldbe\" % \"\u003cversion\u003e\"\n```\n\nThe available packages are:\n* `couldbe`: umbrella meta package to pull in `core` and `cats`\n* `couldbe-core`: minimal implementation to allow basic functionality\n* `couldbe-cats`: extra definitions and functionality for those using the [Cats](https://typelevel.org/cats/) library\n* `couldbe-testsupport`: extra definitions and functionality to support writing tests\n\n\n## Other examples\n```\ndef yourFunction[A: CouldBeGiven, B: CouldHave[PartialOrder], F[_]: CouldBe[Monad]] =\n  // Maybe there was a Given A... maybe there wasn't\n  CouldBeGiven[A].act {\n    // If there is one, do something with it.\n    (a: A) =\u003e doSomethingWith(a)\n  } {\n    // Otherwise perform some fallback behaviour.\n    () =\u003e doSomethingElseWithout()\n  }\n  \n  // Maybe F is a Monad... maybe it isn't\n  CouldBe[Monad, F].act {\n    // If it is, do something monadic\n    (monad: Monad[F]) =\u003e doSomethingMonadic(monad)\n  } {\n    // Otherwise perform some fallback behaviour.\n    () =\u003e doSomethingUnmonadic()\n  }\n```\n\n## Authors\n\n* **Chris Throup** - [github](https://github.com/throup) - [linkedin](https://www.linkedin.com/in/christhroup)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthroup%2Fcouldbe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthroup%2Fcouldbe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthroup%2Fcouldbe/lists"}