ZArrow is a functional programming library built to be used with the ZIO ecosystem.
The library implements the type ZArrow[I, R, E, O]. Each instance of ZArrow describes an effectful mapping from I to O. Specifically, it maps any I to a ZIO[R, E, O], which is a computation that requires an R and either succeeds with an O, fails with an E, or dies.
While ZIO provides features to simplify working with effects, this library aims to further simplify working with effectful mappings. It offers a set of factory methods to lift compatible values into a ZArrow, which can then be transformed using a comprehensive set of operators (e.g., imap, map, flatMap, combine, etc.).
A ZIO[R, E, A] can be thought of as a function R => Either[E, A] where R, called the environment, is passed implicitly (given/implicit parameter).
On the other hand, a ZArrow[I, R, E, O] can be thought of as a function I => R => Either[E, O] where I is passed explicitly and R is passed implicitly.
Another way to look at a ZArrow[I, R, E, O] is to think about it as a ZIO[R, E, O] to which another input channel I was added.
To use ZArrow in your Scala project, add the following dependencies to your build.sbt:
libraryDependencies += "dev.zio" %% "zio" % zioVersion
libraryDependencies += "be.broij" %% "zarrow" % zArrowVersionWe provide an overview of the utilities this library offers. Each method mentioned in the following sections is fully documented in the source code. For further information, please refer to that documentation.
One can create a ZArrow from scratch using:
ZArrow.unitZArrow.identity
One can access a ZArrow from the ZIO environment using the method ZArrow.service.
One can lift compatible values into a ZArrow using the following factory methods:
ZArrow.succeedZArrow.attemptZArrow.fromZIOZArrow.fromZIOAttempt
Each ZArrow[I, R, E, O] has an apply method that allows to compute the ZIO[R, E, O] a value of type I is mapped to.
One can transform a ZArrow using a variety of operators:
layercombine(or<*>)combinePar(or<&>)zipzipParfirstsecondandThen(or>>>)compose(or<<<)errorAndThenerrorComposecatchAllcatchAllCausemapZIOmapmapAttemptmapErrormapErrorAttemptmapBothimapimapAttemptflatMap(or>>=)flatMapErrorflatMapBothwithFilterswapInputsswapOutputsfilterFirstfilterSecond