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

  • SEARCH
  • Home
  • 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 7826437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:25:02+00:00 2026-06-02T09:25:02+00:00

I’m trying to use Control.Arrow.ArrowTree to build a HTML processing arrow that stops after

  • 0

I’m trying to use Control.Arrow.ArrowTree to build a HTML processing arrow that stops after the first successful transformation (depth-first) in the given tree. I.e. a function with the type

processFirst :: (ArrowTree a, Tree t) => a (t b) (t b) -> a (t b) (t b)

For example, to add the class “first” to the very first list item in a HTML document, one could build the arrow

processFirst (hasName "li" `guards` addAttr "class" "first")

I’m rather new to HXT and I’ve been reading the API docs for a couple of hours now and trying to figure out how to implement processFirst, but I haven’t been able to fit all the pieces together. processTopDownUntil sounded promising at first, but that function only stops the processing for a particular sub-tree, so it will still transform all elements excluding nested ones.

  • 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-06-02T09:25:03+00:00Added an answer on June 2, 2026 at 9:25 am

    I’m not sure I completely understood the question, but I’ll try to answer 🙂

    Lets try the next:

    test = flip runLA undefined $ xshow $
      constA "<xml><x>X1</x><x>X2</x></xml>" >>> xread
      >>> processFirst (hasName "x" `guards` addAttr "class" "first")
    
    processFirst f = f `orElse` processChildren (processFirst f)
    

    The definition of processFirst is the same as definition of processTopDownUntil. This function will output something like:

    ["<xml><x class=\"first\">X1</x><x class=\"first\">X2</x></xml>"]
    

    The problem should be clear — if f fails for the top node, then processFirst will be called for every child. We need a way to abort processing of the other children if f succeeded on some child.

    Possible solution could be to use state arrow:

    processFirst f = fromSLA False process
      where
      process = (getState >>> isA not)
                `guards`
                (f >>> changeState (const $ const True))
                `orElse`
                processChildren process
    

    The idea is to set state when f succeeded and check it before processing.

    Note: now f should be SLA arrow. If it is not what you want, the you can try to collect all children (using e.g. listA) and process them purely.

    So, the solution is not ideal, but I hope it will help you as a starting point.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
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

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.