Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 01 10:11
    @SystemFw banned @Hudsone_gitlab
  • Jan 31 2019 04:19
    404- forked
    404-/fs2
  • Jan 31 2019 03:01
    SethTisue commented #1232
  • Jan 30 2019 17:22
  • Jan 30 2019 13:45
  • Jan 30 2019 10:48
    pchlupacek commented #1406
  • Jan 30 2019 10:47
    pchlupacek commented #1406
  • Jan 30 2019 10:39
    pchlupacek commented #1407
  • Jan 30 2019 09:58
    lJoublanc commented #870
  • Jan 30 2019 09:42
    vladimir-popov commented #1407
  • Jan 30 2019 08:10
    vladimir-popov closed #1407
  • Jan 30 2019 08:10
    vladimir-popov commented #1407
  • Jan 29 2019 19:20
    SystemFw commented #1407
  • Jan 29 2019 19:20
    SystemFw commented #1407
  • Jan 29 2019 18:57
    SystemFw commented #1406
  • Jan 29 2019 17:47
    pchlupacek commented #1406
  • Jan 29 2019 17:42
    pchlupacek commented #1406
  • Jan 29 2019 17:39
    pchlupacek commented #1407
  • Jan 29 2019 17:39
    vladimir-popov edited #1407
  • Jan 29 2019 17:38
    vladimir-popov commented #1406
Fabio Labella
@SystemFw
then it should work
Andrey
@404-
i'd like the resulting stream of pairs to terminate only hen both input streams terminate
yes, that made it work
val nums  = Stream.range[IO](1, 10).metered(25.millis)
val chars = Stream.range[IO]('a', 'z' + 1).map(_.toChar).metered(10.millis)
val zipped = for {
  a <- nums.noneTerminate.hold(1L.some)
  b <- chars.noneTerminate.hold('\0'.some)
  c <- (a, b).tupled.map(_.tupled).discrete.unNoneTerminate
} yield c
the nested Options get tricky
Fabio Labella
@SystemFw
does it do what you want though?
val nums  = Stream.range[IO](1, 10).metered(1.second)
val chars = Stream.range[IO]('a', 'z' + 1).map(_.toChar).metered(500.millis)

val zipped = for {
    a <- nums.noneTerminate.hold(0L.some)
    b <- chars.noneTerminate.hold('0'.some)
    c <- (a, b).mapN(_ product _).discrete.unNoneTerminate
  } yield c
or do you need different semantics around termination?
Andrey
@404-
yep that's it
ah i knew there was a more elegant way! (a, b).mapN(_ product _)
Gavin Bisesi
@Daenyth
very neat :)
Peter Aaser
@PeterAaser
Very cool and very legal :+1:
PhillHenry
@PhillHenry
Am I missing an import? I get:
Error:(22, 19) value tupled is not a member of (fs2.concurrent.Signal[[x]cats.effect.IO[x],Option[AnyVal]], fs2.concurrent.Signal[[x]cats.effect.IO[x],Option[Char]]) c <- (a, b).tupled.map(_.tupled).discrete.unNoneTerminate

On the:

c <- (a, b).mapN(_ product _).discrete.unNoneTerminate

line

PhillHenry
@PhillHenry
Sorry, mixing my windows. The error on this line is:
Error:(18, 19) value mapN is not a member of (fs2.concurrent.Signal[[x]cats.effect.IO[x],Option[AnyVal]], fs2.concurrent.Signal[[x]cats.effect.IO[x],Option[Char]]) c <- (a, b).mapN(_ product _).discrete.unNoneTerminate
Andrey
@404-
just import cats.implicits._ should be enough
PhillHenry
@PhillHenry
(the first error is what I get from @404- 's code)
@404- I already am
Gavin Bisesi
@Daenyth
Option[AnyVal] is strange for sure
What version of fs2 are you on?
Andrey
@404-
here's the full example that i run locally:
Gavin Bisesi
@Daenyth
I think Applicative[Signal[..]] got added later than 1.0.0?
PhillHenry
@PhillHenry
1.0.3
Andrey
@404-
import cats.implicits._
import cats.effect.{ExitCode, IO, IOApp}
import fs2.Stream

import scala.concurrent.duration._

object Zipping extends IOApp {
  override def run(args: List[String]): IO[ExitCode] = {
    val nums  = Stream.range[IO](1, 10).metered(25.millis)
    val chars = Stream.range[IO]('a', 'z' + 1).map(_.toChar).metered(10.millis)

    val zipped = for {
      a <- nums.noneTerminate.hold(1L.some)
      b <- chars.noneTerminate.hold('\0'.some)
      c <- (a, b).mapN(_ product _).discrete.unNoneTerminate
    } yield c

    zipped.evalTap(el => IO { println(el) }).compile.drain.as(ExitCode.Success)
  }
}
Gavin Bisesi
@Daenyth
hmm
implicit def applicativeInstance[F[_]](
      implicit F: Concurrent[F]
  ): Applicative[Signal[F, ?]]
should be resolving
throw in an implicitly[Applicative[Signal[IO, ?]]]?
PhillHenry
@PhillHenry
@404- Yup same error even with your code, verbatim.
Gavin Bisesi
@Daenyth
on the mapN line or the implicitly?
Andrey
@404-
what version of cats are you using?
Gavin Bisesi
@Daenyth
maybe try fixing the AnyVal in there?
PhillHenry
@PhillHenry
cats-core is 1.5.0 and cats-effect is 1.1.0.
Andrey
@404-
i'm on 1.6 and 1.2
(in case that makes a difference)
PhillHenry
@PhillHenry
Curious. Just moved to 1.6 and 1.2 and still the same error
Andrey
@404-
maybe missing some compiler options?
Gavin Bisesi
@Daenyth
-Ypartial-unification?
PhillHenry
@PhillHenry
which compiler options should I use?
Gavin Bisesi
@Daenyth
:point_up:
PU is needed to do just about anything fun with cats
Andrey
@404-
yep
Arnau Abella
@monadplus
Why isn't -Ypartial-unification a compilers default ?
Gavin Bisesi
@Daenyth
It will be later
2.13 I believe
Arnau Abella
@monadplus
How long has been the compiler flag option available ? If I recall correclty, it was implemented by Miles Sabin
Gavin Bisesi
@Daenyth
2.12
compiler plugin for 2.11
Fabio Labella
@SystemFw
believe it or not, I think the issue is '\0'
I think it sees like a (deprecated) octal or something