scalpel icon indicating copy to clipboard operation
scalpel copied to clipboard

Suggestion : AttributePredicate combinators

Open ocramz opened this issue 2 years ago • 1 comments

When working with large chunks of HTML I found the need for binary combinators to combine predicates such as

(|||), (&&&) :: AttributePredicate -> AttributePredicate -> AttributePredicate
(|||) = liftAttributePredicate2 (||)
(&&&) = liftAttributePredicate2 (&&)

liftAttributePredicate2 :: (Bool -> Bool -> Bool)
                        -> AttributePredicate -> AttributePredicate -> AttributePredicate
liftAttributePredicate2 h (MkAttributePredicate f) (MkAttributePredicate g) =
  MkAttributePredicate $ \x -> f x `h` g x

which are a bit "lighter" than using match.

ocramz avatar Jan 22 '23 05:01 ocramz

Sounds reasonable, though I think I would suggest different operators since ||| and &&& already exist for arrows.

Maybe @&& and @|| which keeps with the pattern of existing attribute operators @=, @=~, and @:.

fimad avatar Feb 06 '23 02:02 fimad