{"id":13399214,"url":"https://github.com/scalaz/scalaz","last_synced_at":"2025-05-13T15:10:11.899Z","repository":{"id":37444788,"uuid":"474633","full_name":"scalaz/scalaz","owner":"scalaz","description":"Principled Functional Programming in Scala","archived":false,"fork":false,"pushed_at":"2025-05-09T07:54:24.000Z","size":101277,"stargazers_count":4669,"open_issues_count":158,"forks_count":703,"subscribers_count":205,"default_branch":"master","last_synced_at":"2025-05-09T08:35:21.146Z","etag":null,"topics":["functional-programming","scala","scala-native","scalajs","scalaz"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scalaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2010-01-16T06:18:51.000Z","updated_at":"2025-05-09T07:54:27.000Z","dependencies_parsed_at":"2023-10-12T15:26:57.790Z","dependency_job_id":"54cc94c2-3111-4d72-8252-abb45dfa7339","html_url":"https://github.com/scalaz/scalaz","commit_stats":null,"previous_names":[],"tags_count":166,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalaz%2Fscalaz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalaz%2Fscalaz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalaz%2Fscalaz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalaz%2Fscalaz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scalaz","download_url":"https://codeload.github.com/scalaz/scalaz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969247,"owners_count":21992263,"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":["functional-programming","scala","scala-native","scalajs","scalaz"],"created_at":"2024-07-30T19:00:35.317Z","updated_at":"2025-05-13T15:10:06.844Z","avatar_url":"https://github.com/scalaz.png","language":"Scala","funding_links":[],"categories":["Scala","Libraries","Table of Contents","Extensions","Functional Programming","\u003ca name=\"Scala\"\u003e\u003c/a\u003eScala"],"sub_categories":["[Scala](https://github.com/scala/scala)","Extensions"],"readme":"# Scalaz\n\nScalaz is a Scala library for functional programming.\n\nIt provides purely functional data structures to complement those from the Scala standard library.\nIt defines a set of foundational type classes (e.g. `Functor`, `Monad`) and corresponding instances for\na large number of data structures.\n\n[![IRC](https://img.shields.io/badge/chat-on%20libera-brightgreen.svg)](irc://irc.libera.chat/scalaz)\n\n## Getting Scalaz\n\nThe current stable version is 7.3.8, which is cross-built against Scala 2.12.x, 2.13.x, 3.x and Scala.js, scala-native.\n\nIf you're using SBT, add the following line to your build file:\n\n```scala\nlibraryDependencies += \"org.scalaz\" %% \"scalaz-core\" % \"7.3.8\"\n```\n\nFor Maven and other build tools, you can visit [search.maven.org](https://search.maven.org/search?q=g:org.scalaz%20AND%20v:7.3.8).\n(This search will also list all available modules of scalaz.)\n\nTo get sample configurations, click on the version of the module you are interested in.\nYou can also find direct download links at the bottom of that page. Choose the file ending in `7.3.8.jar`.\n\n## Quick Start\n\n```scala\nimport scalaz._\nimport std.option._, std.list._ // functions and type class instances for Option and List\n\nscala\u003e Apply[Option].apply2(some(1), some(2))((a, b) =\u003e a + b)\nres0: Option[Int] = Some(3)\n\nscala\u003e Traverse[List].traverse(List(1, 2, 3))(i =\u003e some(i))\nres1: Option[List[Int]] = Some(List(1, 2, 3))\n```\n\nUse of the `Ops` classes, defined under `scalaz.syntax`.\n\n```scala\nimport scalaz._\nimport std.list._ // type class instances for List\nimport syntax.bind._ // syntax for the Bind type class (and its parents)\n\nscala\u003e List(List(1)).join\nres0: List[Int] = List(1)\n\nscala\u003e List(true, false).ifM(List(0, 1), List(2, 3))\nres1: List[Int] = List(0, 1, 2, 3)\n```\n\nWe've gone to great lengths to give you an *a-la-carte* importing experience, but if you prefer an all-you-can-eat\nbuffet, you're in luck:\n\n```scala\nimport scalaz._\nimport Scalaz._\n\nscala\u003e NonEmptyList(1, 2, 3).cojoin\nres0: scalaz.NonEmptyList[scalaz.NonEmptyList[Int]] = NonEmptyList(NonEmptyList(1, 2, 3), NonEmptyList(2, 3), NonEmptyList(3))\n\nscala\u003e 1.node(2.leaf, 3.node(4.leaf))\nres1: scalaz.Tree[Int] = \u003ctree\u003e\n\nscala\u003e List(some(1), none).suml\nres2: Option[Int] = Some(1)\n```\n\n## Resources\n\nLet the types speak for themselves via the [Scalaz Scaladocs](https://scalaz.github.io/scalaz/#scaladoc)!\n\nThe [examples module](https://github.com/scalaz/scalaz/tree/master/example/src/main/scala/scalaz/example) contains some snippets of Scalaz usage.\n\nThe [wiki](https://github.com/scalaz/scalaz/wiki) contains release and migration information.\n\nTalk with us by joining [IRC: irc.libera.chat channel #scalaz](https://web.libera.chat/#scalaz), or join [the Scalaz mailing list on Google Groups](https://groups.google.com/group/scalaz).\n\nThe [typelevel blog](https://typelevel.org/blog/) has some great posts such as [Towards Scalaz](https://typelevel.org/blog/2013/10/13/towards-scalaz-1.html) by [Adelbert Chang](https://twitter.com/adelbertchang).\n\n[Learning Scalaz](http://eed3si9n.com/learning-scalaz/index.html) is a great series of blog posts by [Eugene Yokota](https://twitter.com/eed3si9n). Thanks, Eugene!\n\n## Changes in Version 7\n\nScalaz 7 represents a major reorganization of the library. We have taken a fresh look\nat the challenges of encoding type classes in Scala, in particular at when and how to\nemploy the implicit scope.\n\n### At a glance\n\n* `scalaz.{effect, iteratee}` split to separate sub-projects; `scalaz.{http, geo}` dropped.\n* Refined and expanded the type class hierarchy.\n* Type class instances are no longer defined in the companion objects of the type class.\n  Instances for standard library types are defined under `scalaz.std`, and instances for\n  Scalaz data types are defined in the companion object for those types. An instance definition\n  can provide multiple type classes in a single place, which was not always possible in Scalaz 6.\n* Type class instances have been organized to avoid ambiguity, a problem that arises when\n  instances are dependent on other instances (for example, `Monoid[(A, B)]`)\n* Use of implicit views to provide access to Scalaz functionality as extension methods\n  has been segregated to `scalaz.syntax`, and can be imported selectively, and need not\n  be used at all.\n* Related functions are defined in the type class trait, to support standalone\n  usage of the type class. In Scalaz 6, these were defined in `Identity`, `MA`, or `MAB`.\n* New data structures have been added, and existing ones generalized. A number of monad\n  transformers have been provided, in some cases generalizing old data structures.\n\n### Modularity\n\nScalaz has been modularised.\n\n* **scalaz-core**: Type class hierarchy, data structures, type class instances for the Scala and Java standard libraries,\n                 implicit conversions / syntax to access these.\n* **scalaz-effect**: Data structures to represent and compose IO effects in the type system.\n* **scalaz-iteratee**: Experimental new Iteratee implementation\n\n### Type Class Hierarchy\n\n* Type classes form an inheritance hierarchy, as in Scalaz 6. This is convenient both at the call site and at the\n  type class instance definition. At the call site, it ensures that you can call a method requiring a more general\n  type class with an instance of a more specific type class:\n\n```scala\ndef bar[M[_]: Functor] = ()\n\ndef foo[M[_]: Monad] = bar[M] // Monad[M] is a subtype of Functor[M]\n```\n\n* The hierarchy itself is largely the same as in Scalaz 6. However, there have been a few\n adjustments, some method signatures have been adjusted to support better standalone usage, so code depending on these will\n need to be re-worked.\n\n### Type Class Instance Definition\n\n* *Constructive* implicits, which create a type class instance automatically based on instances of\n  all parent type classes, are removed. These led to subtle errors with ambiguous implicits, such as\n  this problem with [FunctorBindApply](https://stackoverflow.com/questions/7447591/how-do-i-use-name-as-an-applicative/7448111#7448111)\n* Type class instances are no longer declared in fragments in the companion objects of the type class. Instead, they\n  are defined in the package `scalaz.std`, and must be imported. These instances are defined in traits which will be\n  mixed together into an object for importing *en-masse*, if desired.\n* A single implicit can define a number of type class instances for a type.\n* A type class definition can override methods (including derived methods) for efficiency.\n\nHere is an instance definition for `Option`. Notice that the method `map` has been overridden.\n\n```scala\n  implicit val option: Traverse[Option] with MonadPlus[Option] = new Traverse[Option] with MonadPlus[Option] {\n    def point[A](a: =\u003e A) = Some(a)\n    def bind[A, B](fa: Option[A])(f: A =\u003e Option[B]): Option[B] = fa flatMap f\n    override def map[A, B](fa: Option[A])(f: A =\u003e B): Option[B] = fa map f\n    def traverseImpl[F[_], A, B](fa: Option[A])(f: A =\u003e F[B])(implicit F: Applicative[F]) =\n      fa map (a =\u003e F.map(f(a))(Some(_): Option[B])) getOrElse F.point(None)\n    def empty[A]: Option[A] = None\n    def plus[A](a: Option[A], b: =\u003e Option[A]) = a orElse b\n    def foldR[A, B](fa: Option[A], z: B)(f: (A) =\u003e (=\u003e B) =\u003e B): B = fa match {\n      case Some(a) =\u003e f(a)(z)\n      case None =\u003e z\n    }\n  }\n```\n\nTo use this, one would:\n\n```scala\nimport scalaz.std.option.optionInstance\n// or, importing all instances en-masse\n// import scalaz.Scalaz._\n\nval M = Monad[Option]\nval oi: Option[Int] = M.point(0)\n```\n\n### Syntax\n\nWe co-opt the term *syntax* to refer to the way we allow the functionality of Scalaz to be\ncalled in the `object.method(args)` form, which can be easier to read, and, given that type inference\nin Scala flows from left-to-right, can require fewer type annotations.\n\n* No more `Identity`, `MA`, or `MAB` from Scalaz 6.\n* Syntax is segregated from rest of the library, in a sub-package `scalaz.syntax`.\n* All Scalaz functionality is available *without* using the provided syntax, by directly calling methods\n  on the type class or its companion object.\n* Syntax is available *a-la-carte*. You can import the syntax for working with particular\n  type classes where you need it. This avoids flooding the autocompletion in your IDE with\n  every possible extension method. This should also help compiler performance,\n  by reducing the implicit search space.\n* Syntax is layered in the same way as type classes. Importing the syntax for, say, `Applicative`\n  will also provide the syntax for `Apply` and `Functor`.\n\nSyntax can be imported in two ways. Firstly, the syntax specialized for a particular instance\nof a type class can be imported directly from the instance itself.\n\n```scala\n// import the type class instance\nimport scalaz.std.option.optionInstance\n\n// import the implicit conversions to `MonadOps[Option, A]`, `BindOps[Option, A]`, ...\nimport optionInstance.monadSyntax._\n\nval oi: Option[Option[Int]] = Some(Some(1))\n\n// Expands to: `ToBindOps(io).join`\noi.join\n```\n\nAlternatively, the syntax can be imported for a particular type class.\n\n```scala\n// import the type class instance\nimport scalaz.std.option.optionInstance\n\n// import the implicit conversions to `MonadOps[F, A]`, `BindOps[F, A]`, ...\nimport scalaz.syntax.monad._\n\nval oi: Option[Option[Int]] = Some(Some(1))\n\n// Expands to: ToBindOps(io).join\noi.join\n```\n\nFor some degree of backwards compatibility with Scalaz 6, the über-import of `import scalaz.Scalaz._`\nwill import *all* implicit conversions that provide syntax (as well as type class instances and other\nfunctions). However, we recommend to review usage of this and replace with more focussed imports.\n\n### Standalone Type Class Usage\n\nType classes should be directly usable, without first needing to trigger implicit conversions. This might be\ndesirable to reduce the runtime or cognitive overhead of the pimped types, or to define your own pimped\ntypes with a syntax of your choosing.\n\n* The methods in type classes have been curried to maximize type inference.\n* Derived methods, based on the abstract methods in a type class, are defined in the type class itself.\n* Each type class companion object is fitted with a convenient `apply` method to obtain an instance of the type class.\n\n```scala\n    // Equivalent to `implicitly[Monad[Option]]`\n    val O = Monad[Option]\n\n    // `bind` is defined with two parameter sections, so that the type of `x` is inferred as `Int`.\n    O.bind(Some(1))(x =\u003e Some(x * 2))\n\n    def plus(a: Int, b: Int) = a + b\n\n    // `Apply#lift2` is a function derived from `Apply#ap`.\n    val plusOpt = O.lift2(plus)\n```\n\n### Type Class Instance Dependencies\n\nType class instances may depend on other instances. In simple cases, this is as straightforward as adding an implicit\nparameter (or, equivalently, a context bound), to the implicit method.\n\n```scala\n  implicit def optionMonoid[A: Semigroup]: Monoid[Option[A]] = new Monoid[Option[A]] {\n    def append(f1: Option[A], f2: =\u003e Option[A]): Option[A] = (f1, f2) match {\n      case (Some(a1), Some(a2)) =\u003e Some(Semigroup[A].append(a1, a2))\n      case (Some(a1), None) =\u003e f1\n      case (None, Some(a2)) =\u003e f2\n      case (None, None) =\u003e None\n    }\n\n    def zero: Option[A] = None\n  }\n```\n\nType class instances for 'transformers', such as `OptionT`, present a more subtle challenge. `OptionT[F, A]`\nis a wrapper for a value of type `F[Option[A]]`. It allows us to write:\n\n```scala\nval ot = OptionT(List(Some(1), None))\not.map((a: Int) =\u003e a * 2) // OptionT(List(Some(2), None))\n```\n\nThe method `OptionT#map` requires an implicit parameter of type `Functor[F]`, whereas `OptionT#flatMap`\nrequires one of type `Monad[F]`. The capabilities of `OptionT` increase with those of `F`. We need to encode\nthis into the type class instances for `[a]OptionT[F[A]]`.\n\nThis is done with a hierarchy of [type class implementation traits](https://github.com/scalaz/scalaz/blob/v7.1.2/core/src/main/scala/scalaz/OptionT.scala#L122)\nand a corresponding set of [prioritized implicit methods](https://github.com/scalaz/scalaz/blob/v7.1.2/core/src/main/scala/scalaz/OptionT.scala#L24).\n\nIn case of ambiguous implicits, Scala will favour one defined in a sub-class of the other. This is to avoid ambiguity\nwhen in cases like the following:\n\n```scala\ntype OptionTList[A] = OptionT[List[A]]\nimplicitly[Functor[OptionTList]]\n\n// Candidates:\n// 1. OptionT.OptionTFunctor[List](implicitly[Functor[List]])\n// 2. OptionT.OptionTMonad[List](implicitly[Functor[List]])\n// #2 is defined in a subclass of the enclosing class of #1, so #2 is preferred.\n```\n\n### Transformers and Identity\n\nA stronger emphasis has been placed on transformer data structures (aka Monad Transformers). For example `State` is now\na type alias for `StateT[Id, A, B]`.\n\n`Id` is defined in the `scalaz` package object as:\n\n```scala\ntype Id[A] = A\n```\n\n## Contributing\n\n[Documentation for contributors](https://github.com/scalaz/scalaz/blob/master/CONTRIBUTING.md)\n\n## Credits\n\nSupport for Scalaz development is provided by [Jetbrains](https://www.jetbrains.com/idea/).\n\nThanks to Mark Harrah and the sbt contributors for providing [our build tool](https://www.scala-sbt.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalaz%2Fscalaz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscalaz%2Fscalaz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalaz%2Fscalaz/lists"}