Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 05 2019 14:43
    @typelevel-bot banned @jdegoes
  • Jan 31 2019 21:17
    codecov-io commented #484
  • Jan 31 2019 21:08
    scala-steward opened #484
  • Jan 31 2019 18:19
    andywhite37 commented #189
  • Jan 31 2019 02:41
    kamilongus starred typelevel/cats-effect
  • Jan 30 2019 00:01
    codecov-io commented #483
  • Jan 29 2019 23:51
    deniszjukow opened #483
  • Jan 29 2019 23:37
  • Jan 29 2019 23:22
  • Jan 29 2019 20:26
    Rui-L starred typelevel/cats-effect
  • Jan 29 2019 18:01
    jdegoes commented #480
  • Jan 29 2019 17:04
    thomaav starred typelevel/cats-effect
  • Jan 28 2019 17:43
    asachdeva starred typelevel/cats-effect
  • Jan 28 2019 07:12
    alexandru commented #480
  • Jan 28 2019 05:45
    codecov-io commented #482
  • Jan 28 2019 05:35
    daron666 opened #482
  • Jan 27 2019 13:56
    codecov-io commented #481
  • Jan 27 2019 13:46
    lrodero opened #481
  • Jan 27 2019 05:47
    codecov-io commented #460
  • Jan 27 2019 05:37
    codecov-io commented #460
bifunctor
@bifunctor
@sloshy Could you please explain, how did you do that the akka streams code as "normal Scala" and converted ....
Paul Snively
@paul-snively
@bifunctor: When you run an Akka stream, you get a Future[T]. You can put that expression in IO.fromFuture.
tl;dr Don't run the Akka stream, since Futures start immediately. Put the run expression in IO.fromFuture.
@sloshy : Kinda too bad AWS SDK 2.x uses reactive-streams, but that does present a reasonable use-case for fs2-reactive-streams.
bifunctor
@bifunctor

@paul-snively How could you convert this

    implicit val system = ActorSystem("QuickStart")
    implicit val materializer = ActorMaterializer()
    implicit val executor = system.getDispatcher

    val ticker = Source.tick(0.second, 1.second, 1)
      .runWith(Sink.fromGraph(new StdoutSink))

to IO\?

Paul Snively
@paul-snively
What is ticker's type?
bifunctor
@bifunctor
Sorry
    implicit val system = ActorSystem("QuickStart")
    implicit val materializer = ActorMaterializer()
    implicit val executor = system.getDispatcher

    Source.tick(0.second, 1.second, 1)
      .runWith(Sink.foreach(println))
Paul Snively
@paul-snively
OK. What is that expression's type?
bifunctor
@bifunctor
Int
Paul Snively
@paul-snively
Is it?
Ryan Peters
@sloshy
Should be Future[Done] as mentioned above I think
Paul Snively
@paul-snively
So wrap it in IO.fromFuture.
bifunctor
@bifunctor
Yes, but then I have to run unsafeRunSync
@paul-snively But I would never receive the number 1
try it out
Paul Snively
@paul-snively
Well, you shouldn't. Let's ask this: why do you want to convert the Future to IO?
Better yet: what behavior do you want?
bifunctor
@bifunctor
I would like to use http4s client
that because I have to use IO
Paul Snively
@paul-snively
OK. So you almost certainly want to use IOApp, too.
So ultimately, your app will have a run(args: List[String]): IO[ExitCode] method.
It might contain something like IO.fromFuture(...runWith(Sink.foreach(println))).as[ExitCode.Success]
But at this point, yeah, I have to suggest not using Akka Streams, if you want to use http4s.
bifunctor
@bifunctor
How to get value out of run?
Paul Snively
@paul-snively
Run the application. :-)
The point of IOApp is that it takes care of running the IO[ExitCode] for you.
Well, that's one point, anyway.
bifunctor
@bifunctor
I mean within the Sink.foreach()?
I have combine akka stream with http4s, because I am going to alpakka kafka
Paul Snively
@paul-snively
Consider fs2-kafka instead.
Yout Sink.foreach is calling println, so you should see your output fine.
That is, your whole expression constructs a Future[Done], which has a thread that prints the ticks, right?
bifunctor
@bifunctor
nice thanks
Paul Snively
@paul-snively
Sure!
bifunctor
@bifunctor
fs2-kafka is the solution
Paul Snively
@paul-snively
Well, yes, if your goal is to combine Kafka and http4s.
bifunctor
@bifunctor
yes, that my goal
Paul Snively
@paul-snively
:+1:
bifunctor
@bifunctor
thanks a lot again
Paul Snively
@paul-snively
You bet!
bifunctor
@bifunctor
By the way, what is IO[ExitCode]
Paul Snively
@paul-snively
An IO action that, when eventually evaluated, returns an ExitCode. ExitCode is used to express success or failure of the whole process when the runtime exits.
bifunctor
@bifunctor
What can I do with the ExitCode
Paul Snively
@paul-snively
Use it to express success or failure of your process to the OS.
bifunctor
@bifunctor
Can you please provide an use case?
Paul Snively
@paul-snively
The reason run returns it is IOApp basically wraps main around run, so run needs to return the result main will, in turn, use to construct the exit code for the whole process.
Well, if you return ExitCode.Failure, IIRC, when the JVM halts, Linux (or macOS or whatever) will have its "errno" be -1, or somesuch.
bifunctor
@bifunctor
Thanks a lot
Paul Snively
@paul-snively
:+1:
Matthew DiLoreto
@mjdiloreto
Sorry if this is documented somewhere, but I seem to write a lot of code of the form if(condition) effect else IO(Unit) where effect is IO[Unit]. What's a better way to do this to avoid having to write else IO(Unit)? Right now I just have a function def ifIO(condition: => Boolean, effect:IO[Unit]): IO[Unit] to do that very thing, but I figure this is so simple it must have an idiomatic solution I'm missing.