Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 04:19
    404- forked
    404-/fs2
  • Jan 31 03:01
    SethTisue commented #1232
  • Jan 30 17:22
  • Jan 30 13:45
  • Jan 30 10:48
    pchlupacek commented #1406
  • Jan 30 10:47
    pchlupacek commented #1406
  • Jan 30 10:39
    pchlupacek commented #1407
  • Jan 30 09:58
    lJoublanc commented #870
  • Jan 30 09:42
    vladimir-popov commented #1407
  • Jan 30 08:10
    vladimir-popov closed #1407
  • Jan 30 08:10
    vladimir-popov commented #1407
  • Jan 29 19:20
    SystemFw commented #1407
  • Jan 29 19:20
    SystemFw commented #1407
  • Jan 29 18:57
    SystemFw commented #1406
  • Jan 29 17:47
    pchlupacek commented #1406
  • Jan 29 17:42
    pchlupacek commented #1406
  • Jan 29 17:39
    pchlupacek commented #1407
  • Jan 29 17:39
    vladimir-popov edited #1407
  • Jan 29 17:38
    vladimir-popov commented #1406
  • Jan 29 17:37
    pchlupacek commented #1406
Fabio Labella
@SystemFw
Let me know if you need further help/I've been too cryptic
andrew salvadore
@mericano1
I am slowly wrapping things with side effects, I am sure there are plenty
Fabio Labella
@SystemFw
cool
in doubt, better eval something that doesn't need to
than side-effect something
at least until you have it fully figured out
andrew salvadore
@mericano1
I will def try the above, needed to do exactly that. Just as I have you around. What's the best way to split a stream into two streams?
based on some logic? I am using fs2-http and webSockets
Fabio Labella
@SystemFw
ehm, it might be better if you tell me what's the use case (apologies)
like what do you mean by split?
fs2 is not really based on topology, so to speak
andrew salvadore
@mericano1
fs2 webSocket client is using a Pipe[F, Frame[I], Frame[O]] to communicate with the server
Fabio Labella
@SystemFw
cool
andrew salvadore
@mericano1
that is where I saw the mergeDrainL example
Fabio Labella
@SystemFw
right, so you have this Frames flowing
what do you want to do with them?
andrew salvadore
@mericano1
I am wrapping an API that has multiple endpoints so not all the communication goes back via the webSocket
some of it should be send to the server via webSocket and some should issue some POST to another endpoint
Fabio Labella
@SystemFw
right, so you should send these, and forget about the output
andrew salvadore
@mericano1
I was thinking to map that as a Stream that takes inputs from the server webSocket and then based on the type issues commands that either go back to the server via webSocket or via other REST calls
Fabio Labella
@SystemFw
again, a few different ways of doing this depending on the details
in general, the observe/observeAsync + Sink is a good way of dealing with this
andrew salvadore
@mericano1
:+1: Thanks Fabio, will give it a go. Very helpful
Fabio Labella
@SystemFw
np :+1:
srdjanm88
@srdjanm88
So I'm looking at the code for enqueue1 and I can't really tell when/where the actual queue gets modified. enqueue1 calls offer1, which does a ref.modify but that just seems to return an F[Change[A]](i.e. the actual reference isn't mutated?), which is then used to emit a Signal for the size of the change but that's just kinda it.. I can't see where the actual state in the Ref is mutated/replaced with a new one.
Fabio Labella
@SystemFw
modify returns an F that, when run, will modify the Ref and return a Change containing the old and the new state
@srdjanm88
 qref.modify { s =>
            if (s.deq.isEmpty) s.copy(queue = s.queue :+ a)
            else s.copy(deq = s.deq.tail)
          }
this is where the mutation of the ref is described
srdjanm88
@srdjanm88
Yeah, that's what I thought it did but I'm having trouble getting it to work :< If I have a function where I modify my Ref and I do something like val a = foo(list, addMe) and I do an a.unsafeRunSync, shouldn't I then expect that printing list(a Ref[IO, List[Int]] e.g.) would contain addMe?
Fabio Labella
@SystemFw
sorry, struggling to parse this code
srdjanm88
@srdjanm88
sec, I'll get a little snippet together
val initialChain: IO[Ref[IO, List[Int]]] = refOf(42 :: Nil)
def addLink(chain: IO[Ref[IO, List[Int]]], link: Int): IO[Change[List[Int]]] =
    for {
      ch <- chain
      changed <- ch.modify(link :: _)
    } yield changed

val a = addLink(initialChain, 1010)
println(a.unsafeRunSync)
So the println at the bottom will give me the Change with the correct previous and now fields, but printing initialChain after the unsafeRunSync just gets me the same List(42) as I started with
Fabio Labella
@SystemFw
yes
that's what purely functional means :)
remember that initialChain is not a Ref
it's IO[Ref]
so it will create a new ref every time it's run
call it mkRef
val mkRef: IO[Ref[IO, List[Int]]] = refOf(42 :: Nil)
srdjanm88
@srdjanm88
Oh
is that why like all the Queue code and stuff is in a giant flatMap or whatever?
Fabio Labella
@SystemFw
yes
otherwise we would have all the problems of side effecting code
modify modifies a Ref
but initial it's not a Ref
it's IO[Ref]
srdjanm88
@srdjanm88
That makes sense then, yeah
Fabio Labella
@SystemFw
in practical terms, it means that if you want two different parts of your code to share the same ref
you can't just flatMap a mkRef