zio / zio-prelude

A lightweight, distinctly Scala take on functional abstractions, with tight ZIO integration

Home Page:https://zio.dev/zio-prelude

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Split out Newtype+Subtype functionality to separate, smaller library

bbarker opened this issue · comments

I would like to propose to split out the Newtype/Subtype components as a separate library. This would allow users to benefit from the convenience and safety of newtypes without depending on the whole zio-prelude library.

The motivation for this request comes from a discussion in our organization, where we wanted to create a common library of newtypes for various domains, such as NonEmptyString (but also some domain-specific types). However, we faced some challenges with the current situation:

  • Some of our projects are still using Scala 2, which is not compatible with the neotype library that @kitlangton created for Scala 3.
  • Some of our projects do not want to pull in zio-prelude as a dependency, either because they are using the cats hieararchy, or simply because they are small libraries and we don't want them to have large dependencies.
  • We want to ensure compatibility between newtypes derived from zio-prelude and newtypes derived from the proposed separate library, so that we can use them interchangeably in contract libraries and other shared modules and projects. I believe that this change would help increase the adoption of zio-prelude, if anything since it would make it easier for zio-prelude to have interoperability with projects using what I expect to be the most commonly-desired feature currently in zio-prelude (newtypes).

We appreciate your consideration of this request, and thank you for your great work on zio-prelude! I would be happy to try to do the work on this if it gets the greenlight.

I think I'm 👎 on this. I'm generally negative on "micro-libraries" and I feel like this is one of the top three or four features that you actually use ZIO Prelude for (basically this, operations for combining data types, Validation, and ZPure). I also think it creates maintainability issues by just creating even more projects that need to be maintained and making changes to this functionality that are part of other ZIO Prelude functionality a two step process.

@adamgfraser definitely agreed on not increasing the maintenance cost. But how about we split the current ZIO Prelude library into more modules? That's very cheap to do and maintain.
I volunteer to give it a shot.

I really don't think we need more modules.

I've also been in the situation where I've just wanted to use the zio-prelude newtype functionality when doing domain modeling, in fact I feel like I've asked for this as well in the past (though I never created an issue).

I don't think this makes sense. Newtype and Subtype use a variety of other ZIO Prelude data types and functional abstractions such as Validation and ForEach in their API. This functionality could of course be moved elsewhere but that would not be providing the optimal experience for the majority of users who want multiple features of ZIO Prelude. New types and subtypes aren't something separate but one feature of ZIO Prelude that fits together with the rest of the library. Our goal is to provide an integrated experience where all of this functionality fits together in just the right way, not to carve it up into separate libraries or modules.

I did realize this. Yeah, that makes sense.