2

I´ve been working for a couple years with ReactiveX extension in Java, but now I move to scala, and I´ve seen that many people use the extension ScalaZ to perform more functional programing in Scala.

Is there´s any differences to use ScalaZ extension, or just adapt reactiveX to Scala which I did and I know is playing nice with Scala?.

And after read this blog https://medium.com/@luijar/the-observable-disguised-as-an-io-monad-c89042aa8f31 I though the observable was working as a IO monad as in Scalaz

Regards.

Tomas Mikula
  • 6,537
  • 25
  • 39
paul
  • 12,873
  • 23
  • 91
  • 153
  • 1
    You probably wanted to look at `scalaz-stream`, which is now [FS2 (Functional Streams for Scala)](https://github.com/functional-streams-for-scala/fs2). I don't use it myself, so I can't say how it relates to ReactiveX. – Tomas Mikula Mar 09 '17 at 16:29
  • Thanks I´ll take a look – paul Mar 09 '17 at 17:07

1 Answers1

4

Scalaz and ReactiveX are completely orthogonal to one another.

Scalaz is focused on bringing Category theory à la Haskell to Scala. It brings tons of type classes with Monads and Monoids and other goodies.

ReactiveX on the other hand is more focused on bringing reactive programming concepts to the language. It comes with Observables and Observers.

You can even use RxScala in conjunction with Scalaz! There's a repo called RxScalaz providing some of the typeclass instances of Scalaz for RxScala. Check it out here: https://github.com/everpeace/rxscalaz

If you're happy with "only" using RxScala, then there's no "real" need to accomodate Scalaz into your project.

Luka Jacobowitz
  • 22,795
  • 5
  • 39
  • 57
  • After read this blog I was confuse https://medium.com/@luijar/the-observable-disguised-as-an-io-monad-c89042aa8f31 – paul Mar 09 '17 at 11:17
  • I understand your confusion, but I think the author kind of simplified the relation between the IO Monad and the Observable. If you have any specific question about the differences, I'd be happy to answer :) – Luka Jacobowitz Mar 09 '17 at 11:25
  • Feel free please to elaborate or point me in the right direction about it. Thanks – paul Mar 09 '17 at 11:34
  • `Observable` is like a stream, you can `filter` it, you can only `take` some of it's elements, or you can `drop` some elements. You can `merge`, `combine` or `concat` it with other `Observable`s. None of that is possible with `IO`. `IO` only represents a synchronous chain of computations. For some use cases, yes, they can be extremely similar, but definitely not for all. :) – Luka Jacobowitz Mar 09 '17 at 11:43
  • I can have a chain of computations process in my pipeline using map and flatMap with Observable as Scalaz does, that's why I don't see so much differences – paul Mar 09 '17 at 11:46
  • Yeah, that's what I meant with them being similar in some use cases. If you never use any of the operators besides `map` and `flatMap`, you might be better suited with the Scalaz `Task` which is Scalaz's version of the `IO` Monad. :) – Luka Jacobowitz Mar 09 '17 at 11:58
  • So if for instance then, I just want to use it to handle callbacks between process, I'm good enough with Rx and There's no point to move to Scalaz?. Thanks for all the info by the way – paul Mar 09 '17 at 12:00
  • I can't think of any use case where a `Task` could do something an `Observable` can't. So I'd say you're good enough with Rx, yes :) – Luka Jacobowitz Mar 09 '17 at 12:05
  • Thanks a lot buddy! I will take a look to Scalaz in more detail to have a strong opinion about it anyway – paul Mar 09 '17 at 12:10
  • 1
    No problem at all, don't hesitate to ask any follow up questions :) – Luka Jacobowitz Mar 09 '17 at 12:21