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 8405853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:56:23+00:00 2026-06-09T22:56:23+00:00

I have anti-xml Elem, something like this (auto-generated data): <library> <bookshelf number=0> <book year=1997

  • 0

I have anti-xml Elem, something like this (auto-generated data):

<library>
  <bookshelf number="0">
    <book year="1997" title="Puzzled Coordinators" author="Lily Williams"></book>
    <book year="2005" title="Jittery Fare" author="Lucy Taylor"></book>
    <book year="2001" title="Dizzy Jurisdiction" author="Lucy Robinson"></book>
  </bookshelf>
  <bookshelf number="1">
    <book year="1997" title="Bashful Trusts" author="Lucas Wilson"></book>
    <book year="2003" title="Outrageous Consequences" author="Byron White"></book>
    <book year="1992" title="Irritated Accusations" author="Anne Roberts"></book>
  </bookshelf>
</library>

And I want to apply several transformations to it, for example:

val transforms: Seq[...] = ...
val result = transforms.foldLeft(library)(l,t) => t(l))

But I got only as far as this solution:

val transforms: Seq[Elem => Zipper[Node]] = Seq(
  x => x \\ "book" filter (_.attrs("year").toInt > 2000) unselect,
  x => x \\ "book" filter (_.attrs("title").contains("J")) unselect
)
val result = transforms.foldLeft(lib)((l,t) => t(l).head.asInstanceOf[Elem])

Is there some way to get better types for transformations (Elem => Elem) and avoid those ugly casts?

  • 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-09T22:56:25+00:00Added an answer on June 9, 2026 at 10:56 pm

    Given that unselect currently just returns a Zipper[Node], I don’t see a way to get what you want without bossing the type system around a bit, and that’s going to take something like a cast.

    In this case you really do know something the type system can’t, given the current state of the Anti-XML library: you know that the parent of the zipper resulting from your transformation is a Zipper[Elem], and therefore that what unselect gives you actually will be a Zipper[Elem], even though it’s typed as a Zipper[Node].

    So I think the best you can do is package up the unpleasantness a little more cleanly:

    def toEndo(t: Elem => Zipper[Elem]): Elem => Elem =
      t andThen (_.unselect.head.asInstanceOf[Elem])
    

    Or, to make your intent more apparent:

    def toEndo(t: Elem => Zipper[Elem]) = t andThen (_.unselect.head match {
      case e: Elem => e
      case _ => throw new RuntimeException("Aaaaah! This was never meant to happen!")
    })
    

    Then you can write the following:

    val transforms: Seq[Elem => Zipper[Elem]] = Seq(
      _ \\ "book" filter (_.attrs("year").toInt > 2000),
      _ \\ "book" filter (_.attrs("title").contains("J"))
    )
    
    val result = Function.chain(transforms map toEndo)(lib)
    

    Note that I’ve moved the unselect into the helper to give us a bit more type safety.

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

Sidebar

Related Questions

Suppose I have an XML document stored as an Anti-XML Elem : val root
Suppose I have an Anti-XML object, e.g.: import com.codecommit.antixml._ val child = <child attr=val>...</child>.convert
I cannot get smooth lines for this graph. I have tried anti aliasing, increasing
I have heard a lot about anti patterns and would like to read a
I'm evaluating the Microsoft Anti-Cross Site Scripting Library (AntiXSS V3) I have to say
I have been reading up on Anti-XSS Security Runtime Engine and it looks like
We have a web application that saves survey data in XML format, rather than
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
How can I create anti-noise with code or an application? It doesn't have to
have written this little class, which generates a UUID every time an object of

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.