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 2021 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
Thanks Pavel ;)
Calvin Lee Fernandes
@calvinlfer
hey guys, I have a question about the Pull datatype, what exactly does the R type represent? Can you think of it as some kind of Resource that you can use to produce Os?
Fabio Labella
@SystemFw
no
it's the return type
you can imagine it as a computation the emits some values and emits returns a new thing
it's actually similar to pagination ;)
which is indeed pull-based
Calvin Lee Fernandes
@calvinlfer
so there's two output types? O and R?
Fabio Labella
@SystemFw
R is not an output type, it's a return type
note that to convert a Pull to a Stream
R needs to Unit
Calvin Lee Fernandes
@calvinlfer
oh i see
Fabio Labella
@SystemFw
i.e. a Stream doesn't have the ability to terminate with a value
Calvin Lee Fernandes
@calvinlfer
so R is used to transfer some state between Pulls
but its not used in Stream
Fabio Labella
@SystemFw
Pull and Stream are two "moral" newtype over Algebra
the Stream monad instance (which is on O)
is better for control flow
the Pull monad instance (which is on R) is better for stateful combinators (so for the actual "streaming" aspect)
you can obviously write a combinator in Pull
by recursing and "transferring some state", as you say
and once you're done you convert to Stream
that's how Stream's stateful combinators are done
Calvin Lee Fernandes
@calvinlfer
ahhh
Fabio Labella
@SystemFw
look at uncons on Pull
it returns Pull[F, Nothing, Option(Chunk[O], Stream[F, O])]
Calvin Lee Fernandes
@calvinlfer
thanks! i was using uncons1 and unconsChunk so i was confused what that R type was about
so that emits nothing?
Fabio Labella
@SystemFw
so uncons doesn't emit anything, but returns the first chunk of elements, and the rest of the Stream
similar to list uncons
then you flatMap to get that
Calvin Lee Fernandes
@calvinlfer
ahhh
Fabio Labella
@SystemFw
you can Pull.output on the chunk to emit it
and you have the stream to decide what to do next (recursively)
Calvin Lee Fernandes
@calvinlfer
so is it right to think of R to transfer state between Pulls?
Fabio Labella
@SystemFw
pull-based Streams are iterators on steroid
yeah, in most cases that's how it's used
Calvin Lee Fernandes
@calvinlfer
Streams are crazy!
Fabio Labella
@SystemFw
really focus on the types on Pull, and try writing some stuff with them
note that in Haskell most streaming libraries have 3 type params
one for output, one for result
and the forces you to pick one as the "blessed" one for your Monad instance
but different scenarios work well with difference instance
as I said, an instance on O makes Stream.flatMap behave like a List, and it's great for control flow
an instance on R makes it behave like an iterator, and it's great for stateful combinators and streaming
fs2 separates that into 2 types (Stream and Pull), that wrap the same Algebra (so there' s only one interpreter for both Stream and Pull)
I was confused as to why we needed both at first
but this is actually one of my favourite design decision in the whole of fs2
Calvin Lee Fernandes
@calvinlfer
so in the case of pagination, would you use that R type?
to return the next page to the next Pull and then emit?