sidnt / zionotes

⸮ 🔴zio notes | zio nursery 🔵?
0 stars 0 forks source link

there's no .a #17

Open sidnt opened 4 years ago

sidnt commented 4 years ago

if we have a zio[rea] value, there's no direct api to do .a and access an a:A one of the first things to understand about zio.

the effect has to be run so that it can yield an a. either we can run it then and there itself in a default runtimesystem, like rts.unsafeRun(...) and get the a.

or we wire this effect in multiple other effects, building the program bottoms up, and then at the very top, we have a zio value, that represents our application, which we can then run. and that top, is actually the main method call, that the runtime system underneath, calls in to.

our top level app could be unexceptional. meaning it has fully handled all its domain errors. even if it means just logging all the failures to a file. this handling is just logging all the problems, just that. if it has a declared error type, then in the run interpreter, we have to fold it to a common type. so mostly, we fold it to a non zero int exit code, telling something wrong happened.

and along with it we can even do some side effect in the folding, or a zio effect with foldM.

main's job is to run the method, with the command line arguments. from there, zio runtime system takes over. side effecting calls, like api calls are still happening in the running application, but under the exclusive reins of the zio runtime system. it's like there, the main method call transfers control to the zio runtime system. which then runs the wired in code, accordingly.

sidnt commented 4 years ago

if we want to communicate to an instance of our program, over the network. we could expose an http post api. now what if we want to expose an api for http post requests through this zio program. we will be needing the http server. but where does it fit in with zio?

or we could directly use nio. maybe from there, i could make the zio app read the interrupts that i send over the network to its port.

sidnt commented 4 years ago

imagine a zio:IO[Unit,Int] imagine it reading Ints from several network addresses and then summing them up to return the sum

now it's possible that the failure to get an Int from a network address is represented in constituent zio's error types. but at the topmost level we do .orDie