Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:15:37+00:00 2026-05-28T15:15:37+00:00

I’m trying to write a Conduit using an attoparsec parser. Specifically, given parseOne ::

  • 0

I’m trying to write a Conduit using an attoparsec parser. Specifically, given parseOne :: Parser T, I’d like to construct a Conduit ByteString m T that repeatedly applies the parser to the input and streams the results.

attoparsec-conduit offers sinkParser to turn a Parser into a Sink, but how can I turn this Sink into a Conduit? What I’m looking for is a function like:

conduitSink :: (Resource m) => Sink a m b -> Conduit a m b

which repeatedly feeds data into the Sink, producing each result as it goes. It seems like it could be written fairly easily as a manual loop, but I’m wondering if there’s a better way.

The lack of this seemingly-obvious function in the conduit library makes me think I might be doing something wrong; is there a better way to accomplish this? The use case is turning raw bytes into the parsed form of a message-based network protocol, to be processed by later stages of the pipeline. I already have the opposite direction (i.e. Conduit T m ByteString) thanks to blaze-builder-conduit, so this seemed like the most natural way to structure things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:15:38+00:00Added an answer on May 28, 2026 at 3:15 pm

    You need to use the SequencedSink system for this; it uses a sink and a tracked state to produce a conduit from the repeated application of a sink producer.

    The sink you have created is optimized for incrementally parsing one value, which will be the result at the end of a conduit sequence.

    Since you want this to be part of a conduit pipeline, however, and each chunk of the incoming ByteString might or might not match your parser one or multiple times, you need to take care to get more fine-grained control of the parsing process, passing on the state of an incomplete parse between every application of the sink.

    Assuming, for example, that your parser parses [--] or [----] etc., and T is Int denoting the number of dashes parsed, you need to track the state of the parser as demonstrated by this:

    Input chunk    Sink result - Data.Conduit.SequencedSinkResponse
    [--][---]      Emit Nothing [2, 3]
    [---][---      Emit (Just #func) [3]
    ---------      Emit (Just #func) []
    ]              Emit Nothing [12]
                   Stop
    

    In this case, I use Maybe (ByteString -> Data.Attoparsec.ByteString.Result) as the passed-on state; a different data type might be more suitable depending on the situation.

    This explicit stream treatment is needed to maintain the pipeline nature of the conduit; having the parser conduit be a “bottleneck”, always waiting for enough data to chunk-wise satisfy a parser, would be a major performance sink.

    The implementation of the needed sink should be fairly trivial with the available ResourceT monad interface.

    EDIT: Simply applying your sink in a loop would indeed be the simplest solution, but it will have slightly different performance characteristics if your parser parses short snippets that often end up on the borders of byte chunks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.