iteratee Couple functions for combining Enueratees with Enumerators and Iteratees

John Lato jwlato at gmail.com
Fri Nov 25 11:02:45 GMT 2011


I've been meaning to add these for a while actually; I should be able
to upload a new version after work today.

Would you have any objection to using the same fixities as in the
enumerator package?

John L.

On Fri, Nov 25, 2011 at 6:55 AM, Michael Baikov <manpacket at gmail.com> wrote:
> One more version, clean on typelevel and without unsafeCoerce
>
>
> ($=) :: (Nullable s1, Nullable s2, Monad m) => (forall a. Enumerator
> s1 m a) -> Enumeratee s1 s2 m b -> Enumerator s2 m b
> ($=) enum enee iter = enum (enee iter) >>= run
>
>
> On Fri, Nov 25, 2011 at 2:14 PM, Michael Baikov <manpacket at gmail.com> wrote:
>> Currently we have two nice functions for combining Enumeratees ><> and
>> <>< which can be used to produce chains of Enumeratees. I think that
>> it will be nice to have those functions as well:
>>
>>
>> -- this implementation relies on unsafeCoerce to keep type signature
>> nice and clean
>> -- so it is requred to import Unsafe.Coerce
>>
>> --| Combines Enumerator which produces stream of s and Enumeratee
>> which transforms stream of s to stream
>> -- of s' to into Enumerator which produces stream of s'
>> ($=) :: (Nullable s, Nullable s', Monad m) => Enumerator s m a ->
>> Enumeratee s s' m b -> Enumerator s' m b
>> ($=) enum enee iter = (unsafeCoerce enum) (enee iter) >>= run
>>
>>
>>
>> -- this implementation leaves type signature a bit messy, but without
>> using unsafeCoerce
>>
>> --| Combines Enumerator which produces stream of s and Enumeratee
>> which transforms stream of s to stream
>> -- of s' to into Enumerator which produces stream of s'
>> ($=) :: (Nullable s, Nullable s', Monad m) => Enumerator s m (Iteratee
>> s' m a) -> Enumeratee s s' m a -> Enumerator s' m a
>> ($=) enum enee iter = enum (enee iter) >>= run
>>
>>
>> --| Combines Enumeratee from s to s' and Iteratee which consumes s' to
>> into Iteratee which consumes s
>> (=$) :: (Nullable s, Nullable s', Monad m) => Enumeratee s s' m a ->
>> Iteratee s' m a -> Iteratee s m a
>> (=$) = (.) joinI
>>
>>
>> (=$) is mostly to keep sources clean, but ($=) can be used to
>> enumerate any given Iteratee over list of several different data
>> sources
>> (but type of the source can be transformed to type of Iteratee using
>> Enumeratee) just by transforming them to a single type and performing
>> foldM.
>>
>



More information about the Iteratee mailing list