Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ahoy-jon
Copy link
Contributor

@ahoy-jon ahoy-jon commented Jun 1, 2020

Specializing types on zio.App.

@adamgfraser
Copy link
Contributor

I wonder if there is pedagogical value in not using the type alias here? I usually use App early on in a "Hello, World!" example in ZIO and find it helpful to talk through how this is an effect that can use the ZEnv, can't fail, and returns an exit code. This is obviously the same but the type alias is one more layer of indirection when you're already introducing a lot of new concepts. Maybe it doesn't matter because you could always not use the type alias in educational materials but just a thought.

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Jun 1, 2020

Good point!

I would take another path to improve the pedagogical aspects.
I would use comments (and a different ordering) in package.scala

  type Task[+A]     = ZIO[Any, Throwable, A] // Returns `A`, can fails with `Throwable`, depends on nothing (`Any`).
  type RIO[-R, +A]  = ZIO[R, Throwable, A]   // Like `Task`, but depends on `R`.
  type UIO[+A]      = ZIO[Any, Nothing, A]   // Always returns A, never fails (`Nothing`), depends on nothing (`Any`).
  type URIO[-R, +A] = ZIO[R, Nothing, A]     // Like `UIO`, always returns `A`, never fails (`Nothing`), depends on `R`.
  type IO[+E, +A]   = ZIO[Any, E, A]         // Returns `A`, can fails with `E` , depends on nothing (`Any`)

A lot of learning use navigation in the source (go to declaration, then back navigation).

As for URIO[ZEnv, ExitCode] indeed it is a bit harder at the beginning, but it may help get in ZIO faster and improve thought structure in the long term. (ie, an application depends on ZEnv, always returns an ExitCode). As you see fit!

@luis3m
Copy link
Contributor

luis3m commented Jun 1, 2020

I'd suggest to change the docs as well in case of moving forward with these changes.

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Jun 1, 2020

Sure! Probably a bigger change. I let you guys discuss it if you know which direction it should go.

I was just doing some ZIO blogging and that thing got in the way! 😃

Outside of this PR (I don't have any hard opinion on it):

  • I will try to find better places in ZIO were the type could use an alias.
  • try to work on a scalafix solution to improve code quality by replacing with aliases on an existing codebase.

@adamgfraser
Copy link
Contributor

Okay, let's get this in. I agree we should update the documentation as well and it would be good to add Scaladoc for the type aliases. Do you want to do here or shall we do in a follow up PR?

adamgfraser
adamgfraser previously approved these changes Jun 2, 2020
@ahoy-jon ahoy-jon changed the title Change run(args: List[String]) to URIO[ZEnv, ExitCode] Replace ZIO[R, E, A] by aliases if possible + update documentation Jun 3, 2020
@ahoy-jon ahoy-jon marked this pull request as draft June 3, 2020 01:28
@adamgfraser
Copy link
Contributor

Can ZIO Initellij be used for this? Copying @hmemcpy.

@hmemcpy
Copy link
Contributor

hmemcpy commented Jun 3, 2020

So what is being proposed here? Specialize all ZIO[R, E, A] to aliases? The plugin currently doesn't have this specific functionality as a bulk operation, but I believe this is something I could add!

@adamgfraser
Copy link
Contributor

I think that would be idea. Might be good to have some setting for which ones to rewrite. Like I think the ZIO type aliases are well known so I see the value there but I would wonder if we would want to rewrite all the Managed or STM aliases given the additional indirection and lower user awareness of those type aliases.

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Jun 4, 2020

@hmemcpy would love to use the plugin for that or ScalaFix. (thank you for the plugin, using it)

For information, currently, I am using regexps in IntelliJ to find and replace all occurrences and replace them when needed in the code and in the documentation.

Copy link
Contributor Author

@ahoy-jon ahoy-jon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, checked all the files.

@ahoy-jon ahoy-jon marked this pull request as ready for review June 4, 2020 12:51
@ahoy-jon ahoy-jon requested a review from iravid as a code owner June 4, 2020 12:51
@adamgfraser
Copy link
Contributor

Can you fix the test failures?

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Jun 4, 2020

@adamgfraser sorry, sure will do, I thought It was just some timeout at the beginning. It's back to normal.

btw, @bernit77 is not able to sign the cla, do you know why?

@adamgfraser
Copy link
Contributor

@ahoy-jon Thanks! We're experiencing an issue with the CLA Assistant functionality. I have opened a ticket with them.

Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

@adamgfraser adamgfraser merged commit 5d7c838 into zio:master Jun 4, 2020
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

Successfully merging this pull request may close these issues.

5 participants