Git Product home page Git Product logo

ioeffect's Issues

Fiber compositions does not return any value

Sorry about open here this issue, but to be honest there's no community mature enough in StackOverFlow to help on issues related with this library.

I'm trying to do an example of composition of Fibers, based in the for comprehension that you provide with fibboinachi example

I manage to make it work the fibbonachi, but if you execute this one is not returning anything.
most probably it will be something silly so sorry in advance XD!

@Test
def compositionOfFibersFeature(): Unit = {
  println(s"Before ${Thread.currentThread().getName}")
  def composition: IO[Throwable, String] = for {
    fiber <- createIO("Business logic 1").fork
    fiber1 <- createIO("Business logic 2").fork
    v2 <- fiber1.join
    v1 <- fiber.join
  } yield v1 + v2
  println(s"After: ${Thread.currentThread().getName}")
  unsafePerformIO(composition)
}

private def createIO(sentence:String):IO[Throwable,String] = {
  IO.point[Throwable, String](sentence)
    .map(sentence => {
      sentence.concat(s"$sentence ${Thread.currentThread().getName}").toUpperCase()
    }).delay(1 second)
}

Behave of catchAll

I´m learning the monad IO of scalaZ and I cannot understand how catchAll and catchSome operators works.
I was expecting so see a behave like the onError or onErrorrResumeNext of RxJava, but instead is not catching the throwable, and it´s just breaking the test and throwing the NullPointerException.

Here my two examples

  @Test
  def catchAllOperator(): Unit = {
    val errorSentence: IO[Throwable, String] =
      IO.point[Throwable, String](null)
        .map(value => value.toUpperCase())
        .catchAll(error => IO.fail(error))
    println(unsafePerformIO(errorSentence))

  }

And catchSome example

  @Test
  def catchSomeOperator(): Unit = {
    val errorFunction = new PartialFunction[Throwable /*Entry type*/ , IO[Throwable, String] /*Output type*/ ] {

      override def isDefinedAt(x: Throwable): Boolean = x.isInstanceOf[NullPointerException]

      override def apply(v1: Throwable): IO[Throwable, String] = IO.point("Default value")
    }

    val errorSentence = IO.point[Throwable, String](null)
      .map(value => value.toUpperCase())
      .catchSome(errorFunction)
    println(unsafePerformIO(errorSentence))

  }

Any idea what I´m doing wrong?.

Regards

Minor typo in readme

Readme currently reads:

  def run(args: List[String]): IO[Void, ExitStatus] =
    myAppLogic.attempt.map(_.fold(_ => 1)(_ => 0)).map(ExitStatus.ExitNow(_))

It should read:

  def run(args: List[String]): IO[Void, ExitStatus] =
    myAppLogic.attempt.map(_.fold(_ => 1, _ => 0)).map(ExitStatus.ExitNow(_))

<url> Some(http://github.com/scalaz/effect) </url>

sbt makePom
cat target/scala-2.12/scalaz-ioeffect_2.12-0.0.1-SNAPSHOT.pom
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.scalaz</groupId>
    <artifactId>scalaz-ioeffect_2.12</artifactId>
    <packaging>jar</packaging>
    <description>scalaz-ioeffect</description>
    <url>http://github.com/scalaz/effect</url>
    <version>0.0.1-SNAPSHOT</version>
    <licenses>
        <license>
            <name>BSD3</name>
            <url>https://opensource.org/licenses/BSD-3-Clause</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <name>scalaz-ioeffect</name>
    <inceptionYear>2017</inceptionYear>
    <organization>
        <name>org.scalaz</name>
        <url>http://github.com/scalaz/effect</url>
    </organization>
    <scm>
        <url> Some(http://github.com/scalaz/effect) </url>

addSbtPlugin("com.fommil" % "sbt-sensible" % "2.4.1") bug ? 🤔
https://gitlab.com/fommil/sbt-sensible/blob/36ed88c76e7b249571b951c8ac653ba66b5b00e7/src/main/scala/SonatypePlugin.scala#L131
/cc @fommil

IO.fromFuture

when integrating with existing code, having the ability to create a Task from some Future thing is essential.

But we don't seem to have anything like this... can we please add this?

I'm trying to migrate my work codebase to scalaz.ioeffect from cats-effect right now, so if there are any snippets that I can use as a workaround please do let me know.

note that cats has fromFuture[A](iofa: IO[Future[A]]): IO[A] = ...

which allows deciding if the future begins now or delayed.

Can't compile the main example

I can't compile the example code provided in the README.
I get the following compilation error:

[error] /MyApp.scala:10: overriding method run in trait SafeApp of type (args: List[String])scalaz.ioeffect.IO[scalaz.ioeffect.Void, MyApp.ExitStatus];
[error]  method run has incompatible type
[error]   def run(args: List[String]): IO[Void, ExitStatus] =
[error]       ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Feb 13, 2019 4:34:13 PM

And the following in IntelliJ:

Overriding type List[String] => IO[Void, MyApp.ExitStatus] does not conform to base type List[String] => IO[ioeffect.Void, SafeApp.this.ExitStatus]

Just to be clear, here is the example code from the README that I'm trying to run:

import scalaz.ioeffect.{IO, SafeApp}
import scalaz.ioeffect.console._

import java.io.IOException

object MyApp extends SafeApp {

  def run(args: List[String]): IO[Void, ExitStatus] =
    myAppLogic.attempt.map(_.fold(_ => 1, _ => 0)).map(ExitStatus.ExitNow(_))

  def myAppLogic: IO[IOException, Unit] =
    for {
      _ <- putStrLn("Hello! What is your name?")
      n <- getStrLn
      _ <- putStrLn("Hello, " + n + ", good to meet you!")
    } yield ()
}

I am using Scala 2.11.7 and Scalaz 7.2.27

MonadPlus instance seems wrong

I think we can only provide MonadPlus when E is Unit. Otherwise we can't differentiate between failures and the empty failure, or maybe our Plus logic needs to be more advanced.

unwanted printlns in the default handler

I'm using IO.syncThrowable to invoke a legacy method that can throw an exception.

But even though that's supposed to capture the execption as a valid Task error, not an unexpected exception, I'm still getting the stacktrace dumped to the screen with

scalaz.ioeffect.Errors$UnhandledError: An error was not handled by a fiber: 

I can try to minimise it with an example if this is difficult to see by inspection.

`IO`s created with `par` fail with `ClassCastException` if performed within loop

So it seems something is going on wrong with par implementation, when performed in isolation it seems to work but it starts having unpredictable behavior when performed multiple consecutive times, I realized about this since I have some property-based test with default sampling of 100 performing some IO using par combinator.

You can find the test i'm talking about here: https://github.com/ktonga/scala-poc/blob/topic/parallel-io/src/test/scala/com/brickx/autoinvest/ProgramSpec.scala#L26

This tests used to run ok when IOs were combined using apply2 from default Applicative instance but started failing after I introduced the use of par in this WIP PR: ktonga/scala-poc#6

I'll try to add a minimal example that reproduces the bug to this project for easy debugging.

Cheers.

IO requires Bimap

We currently do not have a bimap for IO. As a bifunctor this is necessary for calling it a bifunctor. If someone wants to implement the new tag and case of the IO runtime supporting it (for instance, as was done with the Map and FlatMap tags), that would be greatly appreciated.

Help me understand racing :)

OK, so here I thought race was straight-forward. Clearly I am doing something wrong...

import $ivy.`org.scalaz::scalaz-ioeffect:2.1.0`, scalaz._, ioeffect._, Scalaz._, scala.concurrent.duration._

object App extends SafeApp {
    type Error = Exception
  
    def run(args: List[String]): IO[Error, Unit] = {
      val io1 = IO.sleep[Error](10.seconds).fork[Error]
      val io2 = IO.point[Error, Unit]{ println("Hello"); Thread.sleep(500L) }.forever[Unit].fork[Error]
      io1.race(io2).toUnit
}

App.main(Array.empty)

I was under the impression the two IO would race each other and once the first one finishes (clearly the sleeper, since the other one is a forever guy), the slower one is interrupted and will never be heard of again.
In the above code io2 is completely unfazed by the race and will keep on running forever. Can an IO.forever not be interrupted?

Anyways, I changed things around a bit, thinking maybe one of the fibres is not allowed to be forked, and now I have this:

import $ivy.`org.scalaz::scalaz-ioeffect:2.1.0`, scalaz._, ioeffect._, Scalaz._, scala.concurrent.duration._

object App extends SafeApp {
  type Error = Exception

  def run(args: List[String]): IO[Error, Unit] = {
    val io1: IO[Error, Unit] = IO.sleep[Error](10.seconds).fork[Error].toUnit
    val io2: IO[Error, Unit] = IO.point(println("Hello")).forever[Unit]
    io1.race(io2)
  }
}

App.main(Array.empty)

a) The race lasts maybe 1 second, not 10, not forever
b) Sometimes I get a bunch of prints but usually only one


Here is essentially what I need (maybe there is a significantly better way to do this):

  • I have two IO[Error, Unit] (let's call them X and Y)
  • X runs forever (it's a streaming processor)
  • Y does a bunch of stuff, then completes
  • I need X to start, then Y to start. Once Y has completed, interrupt X, collect results, done

Thread pool Shifting

@jdegoes I'm wondering is it possible or will be possible in future to shift thread pools? (one thread pool for CPU intense load, another one for blocking operations, etc).

scaladoc is empty

🤔 ?

$ wget https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-ioeffect_2.12/2.0.0/scalaz-ioeffect_2.12-2.0.0-javadoc.jar
$ unzip -Z scalaz-ioeffect_2.12-2.0.0-javadoc.jar 
Archive:  scalaz-ioeffect_2.12-2.0.0-javadoc.jar
Zip file size: 189 bytes, number of entries: 1
-rw----     2.0 fat       25 bX defN 18-Apr-20 23:16 META-INF/MANIFEST.MF
1 file, 25 bytes uncompressed, 27 bytes compressed:  -8.0%

MonadIO instances

I wonder if perhaps we should remove the extends Monad to be able to create instances for the scalaz mtl

Request: Scala Native support

I’m building an app using Scala Native, and pure FP IO is something I’d like to use. It would be great for scalaz-ioeffect to support Scala Native 0.3 like scalaz-core, scalaz-effect, scalaz-iteratee, etc. How difficult is this from a technical perspective?

SNAPSHOT instructions

rather that publish binaries, we should note that this is how to declare a source dependency

val ioeffect = ProjectRef(
  uri("git://github.com/scalaz/ioeffect.git#1a3b397"),
  "ioeffect"
)

and then .dependsOn(ioeffect) instead of libraryDependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.