You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many streaming functions factor through a "fold" that guarantees that they consume their arguments sequentially and transform them with monad homomorphisms before re-emitting them. (cf. foldMap). Is this style something you're interested in pursuing, either internally or in the public API?
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ExistentialQuantification #-}
importqualifiedStreamingasSimportqualifiedStreaming.PreludeasSimportqualifiedControl.Monad.FreeasFimportqualifiedControl.Monad.Trans.WriterasWimportqualifiedData.MonoidasMdataFoldfmn=forallo.Monado=>Fold (foralla.fa->oa)
(foralla.ma->oa)
(foralla.oa->na)
fold:: (Functorf,
Monadn,
Monadm)
=>Foldfmn->S.Streamfma->na
fold fold s =case fold ofFold ff fm fo -> fo (S.iterT f (S.hoist fm s))
where f =S.join . ff
erase::Monadm=>Fold (S.Oft) m (S.StreamS.Identitym)
erase =Fold f S.lift idwhere f (_ S.:> rest) =S.yields (S.Identity rest)
filter::Monadm=>t->Fold (S.OfBool) m (S.Stream (S.OfBool) m)
filterpred=Fold f S.lift idwhere f (a S.:> rest) =if a
thenS.yield a >>return rest
elsereturn rest
with:: (Monadm, Functorf)
=> (a->fx)
->Fold (S.Ofa) m (S.Streamfm)
with g =Fold f S.lift idwhere f (a S.:> rest) =S.yields (g a) >>return rest
-- This one needs a little post processingelem:: (Eqa, Monadm)
=>a->Fold (S.Ofa) m (W.WriterTM.Anym)
elem a' =Fold f S.lift idwhere f (a S.:> rest) =if a == a'
thenW.tell (M.AnyTrue) >>return rest
elsereturn rest
The text was updated successfully, but these errors were encountered:
I'm confused as to what the actual benefit is here - mainly because I think I misunderstand you. What does "consume their argumentssequentially" mean? What are the arguments here? Arguments to the functions defined in streaming? What does sequentially mean? The way it's worded makes it seem to refer to the arguments, but I'm not sure what arguments is, so that doesn't exactly make sense. Do you mean 'linearly' instead of 'sequentially'?
The easiest way to understand what I mean is to look at the code. There exists a function fold such that many of the standard streaming functions are fold . f for some f.
Many
streaming
functions factor through a "fold" that guarantees that they consume their arguments sequentially and transform them with monad homomorphisms before re-emitting them. (cf. foldMap). Is this style something you're interested in pursuing, either internally or in the public API?The text was updated successfully, but these errors were encountered: