View profile

ZIO News - Issue #31

ZIO News - Issue #31
By ZIO News • Issue #31 • View online
Welcome to ZIO News, your newsletter dedicated to ZIO and its ecosystem.
The big reveal at ZIO World 2022 is a HUGE simplification to resource management in ZIO 2.0 that brings new levels of simplicity, power, & performance.
Adam Fraser and John De Goes discovered ZIO Environment is now powerful enough to provide resource-safety by itself!
In ZIO 1.x, we used a data type called Managed to provide resource safety. Although inspired by the Managed data type from Haskell, ZIO Managed innovated in a number of ways over both Haskell and Cats Effect Resource:
  • Managed supported interruptible acquisition, which is useful for concurrent data structures like semaphores, where it is safe to interrupt acquisition because the clean-up can determine (by inspecting in-memory state) whether acquisition succeeded or not.
  • Managed supported parallel operations, all with the most desirable semantics possible. For example, if you acquired resources in parallel, then they would be released in parallel, and if anything went wrong, of course, acquisition would be aborted & resources released.
Managed has an API almost identical to ZIO, by design, so your knowledge of ZIO transfers to Managed. The main difference is that in Managed, `flatMap` lets you use and keep open a resource, while `use` lets you use & release the resource (going back to ZIO).
In addition, Managed has new constructors, so you can create them from a pair of acquire/release actions, or from just a finalizer (which would be invoked during finalization).
Despite the innovation & numerous benefits, however, Managed presents some serious drawbacks:
  • First, Managed is Yet Another Thing to teach to developers. Many new ZIO developers try to avoid using Managed, because they are not sure exactly what it’s for or how it differs from ZIO. Those who use it, sometimes wonder when to use ZIO versus Managed.
  • Second, all the methods on ZIO must be manually and painstakingly re-implemented on Managed, but with much more complex implementations due to the complications of handling resource safety in the presence of concurrency. In practice, ZIO still has more methods than Managed.
  • Third, Managed is a layer over ZIO, and is slower than ZIO itself, because of the additional complications & wrapping. Unlike other approaches, ZIO uses an executable encoding, so it’s able to avoid double-interpretation, but it still has measurable overhead over ZIO.
Despite the drawbacks of Managed, the benefits of concurrent resource safety are significant, so we documented, supported, and tried to optimize Managed over the life of ZIO 1.x, not having a suitable alternative.
With ZIO 2.0, all of this is radically changing for the better!
Thanks to other ZIO 2.0 innovations, including the removal of Has (which bakes a compositional environment directly into the ZIO data type), Adam Fraser and John De Goes have found a way to DELETE Managed entirely, while preserving all of its benefits!
How this works is by making the concept of ‘scopes’ first-class.
In 2.0, a `Scope` is a value that provides two capabilities: adding a finalizer, & closing the scope. Operations that acquire resources add their finalizers directly to the current scope, stored in ZIO Environment.
For example, an operation that opens a file might have this type of signature:
def openFile(name: String): ZIO[Scope, IOException, FileInputStream]
It is implemented by opening the file and ensuring that a close finalizer is added to the current Scope.
To feed a new scope to an effect (and subsequently close the scope), you can use the `ZIO.scoped` operator:
ZIO.scoped {
for {
file <- openFile(name)
result <- useFile(file)
} yield result
}
`ZIO.scoped` eliminates `Scope` from the environment, leaving the rest of the environment unchanged. You can think of it as an algebraic effect handler that handles the `Scope` effect by eliminating it from the set of algebraic effects being used.
This simple, beautiful, & powerful design gives us bulletproof parallel and concurrent operators that may acquire resources with well-defined and optimal semantics in successful and failure scenarios. All the Managed semantics arise for free atop ZIO!
  • Scopes are simple because they don’t require you to learn any new data types.
  • Scopes are powerful, because ZIO has more operators than Managed, and is always ‘up to date’ with the latest and greatest.
  • Scopes are fast because there are no layers atop ZIO.
In addition to providing simpler, more powerful, & faster resource management, the replacement of Managed with scopes is going to TREMENDOUSLY simplify the ZIO API: there will not be any more toManaged, mapManaged, etc, variants. Layers will always be constructed with ZIO. Etc.
Now, for reasons of backward compatibility, Managed won’t actually be deleted, but rather, moved to a separate library that your ZIO 2.0 application can depend on. However, ZIO Core, including ZIO Streams and ZIO Test, will no longer use Managed.
Such a massive simplification to ZIO 2.0, as well as an increase in power and performance, is going to further cement ZIO as the library of choice for forward-thinking companies looking to drive competitive advantages through best-in-class technology.
It’s also a testament to the flexibility and power of ZIO Environment, which we are still learning about.
Rather than blindly copying Haskell, ZIO is boldly charting new ground, discovering novel, more ergonomic, more expressive, and faster ways of solving classic challenges.
Indeed, this innovation is not possible to replicate without ZIO Environment: while our earlier innovations in Managed were easier to replicate, this technique for resource safety simply cannot be brought to any of the mono-functor effect types–it’s a ZIO exclusive!
More generally, ZIO’s decision to adopt typed errors & environment were bold & controversial, but over time, they have opened up new ways of programming that are impossible without these features, resulting in levels of performance, productivity, & type-safety not seen elsewhere.
Even now, we are still learning and discovering the full extent of these capabilities (see ZIO JDBC for another example).
We hope that other libraries and ecosystems learn from our work here, & continue to explore the fertile ground made possible by typed errors & environment.
Stay tuned for our imminent release of the next release candidate for ZIO 2.0, which will bring scopes and other miscellaneous polishing and refinements to ZIO users everywhere.

Major Releases
Release ZIO 2.0.0-RC3
First Release ZIO-SQL 🙌
Type-safe, composable SQL for ZIO applications.
ZIO Ecosystem
ZIO-JDBC 
A small, idiomatic ZIO interface to JDBC.
LeadIQ OSS / Reactivemongo ZIO · GitLab
Blog Articles
About capture checking in Scala 3 by Oleg Nizhnik 👏
Modeling & Building PayRoll Engine Using Functional Effects System With ZIO Asynchronous, Concurrent, ZIO Scala FP Library. HR Use case.
ZIO + Kubernetes |Mark Rudolph
ZIO SQL - type-safe SQL for ZIO applications
Published Talks
What Functional Programming Can Learn From Object-Oriented Programming by John De Goes
What Functional Programming Can Learn From Object-Oriented Programming by John De Goes
In this talk, John A. De Goes will argue that object-oriented programming brings facilities for code organization and architecture that all functional programs can benefit from. Rather than competing with each other, functional programming and object-oriented programming can work in harmony, and Scala can be the language that unites the two in a way not possible with Haskell or other pure functional programming languages. Come see what functional programming can learn from object-oriented programming!
Functional Effects for Everyone by Adam Fraser
Functional Effects for Everyone by Adam Fraser
We want people from all backgrounds to be able to get the benefits of functional programming, but there are obstacles that make that harder than it should be. In this talk, Adam Fraser will look at some of the common pitfalls in working with functional effects and see how ZIO is addressing them in a way that makes life easier for all of us!
ZIO SCHEMA: A Toolkit For Functional Distributed Computing by Dan Harris
ZIO SCHEMA: A Toolkit For Functional Distributed Computing by Dan Harris
Applying statically typed functional programming techniques to distributed systems can often pose significant hurdles. First among these is how we can handle statically typed computations in distributed environments. ZIO Schema is a library that provides a set of tools that can help solve these issues in a type-safe way by reifying Scala types as pure, serializable values.
How could ZIO look like in Scala 3 by Michael Arnaldi
How could ZIO look like in Scala 3 by Michael Arnaldi
We are going to look at how the ZIO API could be improved by leveraging Scala 3. We will look into how to exploit union and intersection types to improve the developer experience of dealing with typed errors and environments. We will further discuss how this design could reduce the boilerplate of using libraries of the ZIO ecosystem.
Introducing ZIO Meta by Damian Reeves
Introducing ZIO Meta by Damian Reeves
Scala 3 has formalized meta-programming in Scala as a concrete discipline; however, in the ZIO ecosystem and the broader Scala ecosystem as a whole, there exists a need to harness the power provided by the new first-class meta-programming capabilities of the language. Runtime reflection has been a tool used to provide information about the structure of user code for decades now on the JVM; however, this tool comes with a cost. What if you could easily extract information about the structure of your code in an easy and composable manner, that works at compile time. This is one of the goals of ZIO Meta.
ZIO HTTP by Tushar Mathur
ZIO HTTP by Tushar Mathur
In this talk, you will learn about how to get started with ZIO HTTP, building your HTTP microservices, and REST API endpoints using the power of functional Scala. We will also look at some of the more advanced features and some bleeding edge stuff that the team has been working on.
ZIO App Architecture by Kit Langton
ZIO App Architecture by Kit Langton
Learn how to architect small, medium, and large applications using the power of ZLayer and ZIO 2.0. Wiring together a large application usually calls for intensive quantities of boilerplate; under the Sturm und Drang of code churn, even the most carefully tended repositories turn to spaghetti by the edges. Instead, with some trusty, battle-tested “best practices”, learn how to architect your ZIO applications such that you can focus on your business logic, while the morale-mulching mundanity of application assembly becomes a near-effortless act of compile-time automaticity.
Moving From Akka To ZIO: Experiences And Comparisons by Jan Ypma
Moving From Akka To ZIO: Experiences And Comparisons by Jan Ypma
In this case study, you will learn how Jan and his team migrated a Scala application from Akka Actors and Akka Streams to ZIO. Connected with Kafka, REST services, and exposing its own REST API, you will learn the decisions that his team made and the lessons they learned.
Zymposium - Aspects
Zymposium - Aspects
Aspects are a way of separating “how” our effects get executed from “what” they are doing. Aspects started with ZIO Test but have since moved to ZIO ecosystem libraries such as Caliban and will be available more generally in ZIO 2.0, so now is a great time to learn about them!
Events
From Twitter
John A De Goes
ZIO 2.0-RC3 🎉

A breakthrough release featuring ZIO Scopes, which radically simplify resource safety to a level NEVER seen before in Scala or Haskell!

Also featuring a simpler, faster, more powerful metrics system, & other goodies like hotswap services!

https://t.co/pkXlzdwAtE
John A De Goes
What's next for ZIO?

1. Get out 2.0 & invest in polishing growing ecosystem

2. Launch backend framework with unheard of productivity & accessibility

3. Reach beyond Scala to bring new devs into fold

4. Hugely increase production of ZIO devs

We're just getting started! 🎉💪
otun oluwaseyi
Check out my latest article: Modeling &amp; Building PayRoll Engine Using Functional Effects System With ZIO Asynchronous, Concurrent, ZIO Scala FP Library. HR Use case. https://t.co/n7HbG7QXWg via @LinkedIn
Milad Khajavi
ZIO 2.0 dramatically simplifies resource safety by removing ZManaged.

If you missed @adamfraser 's talk at ZIO World 2022, don't miss this thread.

One Monad to Rule Them All 👍 https://t.co/agI37vwPp2
Jaro Regec
If you want to try out ZIO SQL 0.0.1 version in your hobby project and are not sure how, check out https://t.co/DqigU4uTho App contains also zio 2.0, zio http and more :) https://t.co/fLZJpEbGUL
Dream11 Engineering
And yet another time #Dream11 has achieved a triumph!

@jdegoes introduced our Dreamster, @dogirdhar at #ZioWorld Event, who is going to talk about ZIO-HTTP, the single most important library in 2022! Proud to be leading at the cutting edge of #tech

@zioscala https://t.co/UUMkfJahfv
Julien Perrochet
Another deceptively powerful thing that @zioscala's zio-streams does out of the box:

`.zipWithLatest()` makes it easy and natural to build reactive apps as soon as you start "thinking in (infinite) streams"
John A De Goes
Years ago, I eschewed subtyping & variance, and tried to make my Scala look like Haskell.

Now, I think OOP brings something NEW to the table.

In this new video, my keynote at Functional Scala 2021, learn about my journey & what FP can learn from OOP!

https://t.co/SmwGdEt8PJ
Daniel Sebban
This version removes ZManaged entirely from zio. Huge simplification indeed, the amount of thought to make zio 2.0 user friendly is staggering, great job @zioscala ! https://t.co/n4hFqM89xO
Nicolas Dasriaux
Handling errors in a functional way. In way that is principled, combines very well, and offers easy to understand mental model to the developper. 👇 https://t.co/6JugvwV638
zio
Effectful Programming In The Subscription Domain by Marianne Pearson at the @DisneyStreaming Engineering Meetup. How her team harnessed ZIO to tackle some of the main challenges building and maintaining subscription service. 👏 https://t.co/ljFY1hlRMM
Did you enjoy this issue?
ZIO News

Everything about ZIO and its ecosystem

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue