Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.wrapAll for multi-type types #1260

Open
domdorn opened this issue Feb 29, 2024 · 0 comments
Open

.wrapAll for multi-type types #1260

domdorn opened this issue Feb 29, 2024 · 0 comments

Comments

@domdorn
Copy link
Contributor

domdorn commented Feb 29, 2024

We currently have a .wrapAll on zio.prelude.Newtype[A] that works on any F[A] and gives us a F[B].
What is missing is a .wrapAll that I can use on a F[A,C] that gives me a F[B,C] as well as one that works
on a F[C,A] that gives me a F[C,B]. Additionally one that I can use from F[A,C] -> F[B,D]

Current use-case is that I have a

object AssetName extends zio.prelude.Newtype[String]
object Timestamp extends zio.prelude.Newtype[Long]

and I want to map a

val myMap: Map[String, Long]

to

val wrappedMap: Map[AssetName, Long]
// and ultimatively 
val finalMap: Map[AssetName, Timestamp]

I can do that by

val wrappedMap = myMap.map {
      case (key, value) => AssetName(key) -> value
    }
// or
val finalMap = myMap.map { 
   case (key, value) => AssetName(key) -> Timestamp(value)
   }    

but as far as I know, this will create subpar bytecode and should be avoided.

Ideally, I'd have something like this:

val wrappedMap1: Map[AssetName, Long] = AssetName.wrapAllT1(myMap)
val wrappedMap2: Map[AssetName, Timestamp] = Timestamp.wrapAllT2(wrappedMap1)

or even better something like

val finalMap: Map[AssetName, Timestamp] = AssetName.zip(Timestamp).wrapAllBoth(myMap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant