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
Gavin Bisesi
@Daenyth
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
Andrey
@404-
that would be hilarious. how so?
what sees it like that? the compiler without the -Ypartial-unification option?
Fabio Labella
@SystemFw
partial unification has nothing to do with it
at least the AnyVal part
the mapN missing might be partial unification, but it's a separate thing
Andrey
@404-
but under what conditions is that reproducible?
Fabio Labella
@SystemFw
which part?
the AnyVal?
Andrey
@404-
right
Fabio Labella
@SystemFw
no idea
I've seen it in the repl, that's all
PhillHenry
@PhillHenry
OK, I added -Ypartial-unification but had to upgrade to Scala 2.12 (I was on 2.11 - sorry!) and it now compiles :)
Andrey
@404-

ah then per earlier comment from @Daenyth

compiler plugin for 2.11

you can stay on 2.11, but you'll need to add an extra compiler plugin
actually, maybe just bumping to latest 2.11 will allow you to use that flag
PhillHenry
@PhillHenry
Thanks. It's only a small project so upgrading to 2.12 is painless.
Andrey
@404-

btw, i spoke to soon earlier. as i said, i wanted:

the resulting stream of pairs to terminate only when both input streams terminate

so, i had to use zipWithPrevious at which point it got pretty gnarly...

val nums  = Stream.range[IO](1, 10).metered(25.millis)
val chars = Stream.range[IO]('a', 'z' + 1).map(_.toChar).metered(10.millis)

type PrevCurr[A] = (Option[A], Option[A])
def noneTermAndZipWithPrev[A]: Pipe[IO, A, PrevCurr[A]] = _
  .noneTerminate
  .zipWithPrevious
  .map { case (prev, curr) => prev.flatten -> curr }

def combine[A, B]: (PrevCurr[A], PrevCurr[B]) => Option[(A, B)] = {
  case ((_, Some(aCurr)), (_, Some(bCurr))) => (aCurr -> bCurr).some
  case ((_, Some(aCurr)), (Some(bPrev), None)) => (aCurr -> bPrev).some
  case ((Some(aPrev), None), (_, Some(bCurr))) => (aPrev -> bCurr).some
  case ((_, None), (_, None)) => None
}

val zipped = for {
  a <- nums.through(noneTermAndZipWithPrev).hold(none[Long] -> 1L.some)
  b <- chars.through(noneTermAndZipWithPrev).hold(none[Char] -> '\0'.some)
  c <- (a, b).mapN(combine).discrete.unNoneTerminate
} yield c
any advice on making that look more sane/pretty?