- Notifications
You must be signed in to change notification settings - Fork22
Fast [co]product types with a clean syntax. For Cats & Scalaz.
License
frees-io/iota
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Iota is a tiny library for fast coproduct types with a syntaxthat cleanly supports the disjunction of any number of types.
Traditional coproduct implementations are implemented as binary treesor linked lists at both the type and value level. The syntax fortraditional coproducts frequently becomes unwieldy as the number ofdisjunct types grows.
// a coproduct of types using scala.util.EithertypeEitherFoo=Either[Int,Either[String,Double]]// a coproduct of type constructors using cats.data.EitherKimportcats.data.EitherKtypeEitherKBar0[A]=EitherK[List,Seq,A]typeEitherKBar[A]=EitherK[Option,EitherKBar0,A]// a coproduct of type constructors using scalaz.Coproductimportscalaz.CoproducttypeCoproductKBar0[A]=Coproduct[List,Seq,A]typeCoproductKBar[A]=Coproduct[Option,CoproductKBar0,A]
Iota coproducts are linked lists at the type level. At the value level,Iota stores the index of the disjunct value's type for quick andconstant time access of the values. This syntax scales cleanly tosupport any number of disjunct types.
// for catsimportiota._importTList.::importTListK.:::// a coproduct of typestypeFoo=Cop[Int::String::Double::TNil]// a coproduct of type constructorstypeBar[A]=CopK[Option:::List:::Seq:::TNilK,A]
// for scalazimportiotaz._importTList.::importTListK.:::// a coproduct of typestypeFoo=Cop[Int::String::Double::TNil]// a coproduct of type constructorstypeBar[A]=CopK[Option:::List:::Seq:::TNilK,A]
To get started with SBT, simply add the following to your build.sbt file.
For Scala 2.11.x and 2.12.x:
libraryDependencies+="io.frees"%%"iota-core"%"0.3.10"// for catslibraryDependencies+="io.frees"%%"iotaz-core"%"0.3.10"// for scalaz
Or, if using Scala.js (0.6.x):
libraryDependencies+="io.frees"%%%"iota-core"%"0.3.10"// for catslibraryDependencies+="io.frees"%%%"iotaz-core"%"0.3.10"// for scalaz
Iota requires either Cats or Scalaz. If you're using Scalaz, use the "iotaz"modules and import from theiotaz
package (instead ofiota
).
Cats friendly terminology (such as "FunctionK") is used in the iotamodules while Scalaz friendly terminology (such as"NaturalTransformation") is used in the iotaz modules. If you find anissue or inconsistency, please file a GitHub issue and it will be fixed.
The Cats examples will work against Scalaz, and vise versa, so long as thelibrary specific terminology is adjusted. Expect more Scalaz examples as theIota library evolves.
Seedocs/cats.md for the Cats specific documentation anddocs/scalaz.md for the Scalaz specific documentation.
If you wish to add your library here please consider a PR to include it in the list below.
47 Degrees offers commercial support for the iota library and associated technologies. To find out more, visit47 Degrees' Open Source Support.
Iota is designed and developed by 47 Degrees
Copyright (C) 2016-2018 47 Degrees.http://47deg.com
About
Fast [co]product types with a clean syntax. For Cats & Scalaz.