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
so, forgetting about Stream for a second
most people understand F and O in Pull very easily
but R is more confusing
what is that for?
Gavin Bisesi
@Daenyth
I'm also wondering about how it relates to transforming the Stream of IO for example into an IO of the final result
and where R fits into that if pull generalizes stream
Fabio Labella
@SystemFw
no, that's a different concept (although I see why they might look related)
Gavin Bisesi
@Daenyth
:+1:
go on
Peter Aaser
@PeterAaser
btw, from the codebase:
* `Pull` forms a monad in `R` with `pure` and `flatMap`:
Fabio Labella
@SystemFw
so, a Pull can emit some elements and then terminate with a result
Gavin Bisesi
@Daenyth
ok
Fabio Labella
@SystemFw
that result can be used to mean "the rest"
so imagine a function with an accumulator for Lists
you do some stuff, then recur with the rest of the list
and in the end return the final List
and indeed that was the attempt by OP
however is a bit different when streaming
you don't want to build up the whole result
as soon as something needs emission you want to describe the action of emitting it
but you still want the property of "the rest of the stuff", to be able to write recursive functions
Gavin Bisesi
@Daenyth
mhm
Fabio Labella
@SystemFw
does it make sense? if not, what's confusing about it?
Peter Aaser
@PeterAaser
and no sooner
Fabio Labella
@SystemFw
(I'm not done, but it's a good checkpoint)
Justin Heyes-Jones
@justinhj
is the result type R always the 'tail' of the stream that the pull is not interested in?
Gavin Bisesi
@Daenyth
I'm not 100% there
but I think it might be good to keep going - once I get to a concrete example I think things will click a bit
Fabio Labella
@SystemFw
@justinhj in most examples, yes
right
so, let's see how to translate these concepts to code
small simplification, I'm going to ignore Segment for now, and talk about uncons1/output1 and not about uncons/output
this is Pull.output
object Pull {
   ....
   def output1[F[_], O](o: O): Pull[F, O, Unit]
}
output1 takes an element, and gives a Pull that describes the concept of emitting that one value
the return type is Unit there
how do we return something instead? (so, terminate with a value)
Pull forms a Monad in R
Gavin Bisesi
@Daenyth
are we talking in the mathematical sense?
or a Monad typeclass instance
Peter Aaser
@PeterAaser
Pull does form a monad
Fabio Labella
@SystemFw
typeclass instance (and also math sense ofc)
Peter Aaser
@PeterAaser
you can use for
Fabio Labella
@SystemFw
object Pull {
 ....
def pure[F[_], R](r: R): Pull[F, Nothing, R]
}
calling pure gives you a Pull that describes the action of finishing the Pull with a value R
Gavin Bisesi
@Daenyth
ok
Fabio Labella
@SystemFw
O is Nothing because nothing is emitted
and flatMap takes an R => Pull
now let's tie in with Stream and it will make more sense I think
Gavin Bisesi
@Daenyth
R being the varying parameter in >>=