on -package:esqueleto

on b u x y runs the binary function b on the results of applying unary function u to two arguments x and y. From the opposite perspective, it transforms two inputs and combines the outputs.
((+) `on` f) x y = f x + f y
Typical usage: sortBy (compare `on` fst). Algebraic properties:
  • (*) `on` id = (*) -- (if (*) ∉ {⊥, const
    ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g .
    f)
Perform an action in response to a signal. Use it like this:
on obj sig $ do
...
or if the signal handler takes any arguments:
on obj sig $ \args -> do
...
Connect a signal to a signal handler.
Build an attribute from a foreground color and a background color. Intended to be used infix.
(*) `on` f = \x y -> f x * f y. Typical usage: sortBy (compare `on` fst). Algebraic properties:
  • (*) `on` id = (*) (if (*) ∉ {⊥, const ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g .
    f)
Apply an implication to a predicate in the implicit context. The (a ~~ n) parameter is not actually used; it's type is used to help select a specific fact from the context. @ -- A safe head function, using an implicitly-passed safety proof. head :: Fact (IsCons xs) => ([a] ~~ xs) -> a head xs = Prelude.head (the xs)
  • - Reverse, and a lemma. reverse :: ([a] ~~ xs) -> ([a] ~~ Reverse xs) revConsLemma :: Proof (IsCons xs) -> Proof (IsCons (Reverse xs))
  • - Implement a safe last function. last :: Fact (IsCons xs) => ([a] ~~ xs) -> a last xs = note (revConsLemma on xs) $ head (reverse xs)
Connect the given signal to a signal handler.
The composition of two AD modes is an AD mode in its own right
Lift a binary function to the domain of a projection.

Example

>>> :kind! Eval (((&&) `On` Fst) '( 'True, 'Nothing) '( 'False, 'Just '()))
Eval (((&&) `On` Fst) '( 'True, 'Nothing) '( 'False, 'Just '())) :: Bool
= 'False
Activate setting
Vega event stream selector that triggers a selection, or the empty string (which sets the property to false).
Ontario
Like finally, but only performs the final action if there was an exception raised by the computation.
A more concise version of complement zeroBits.
>>> complement (zeroBits :: Word) == (oneBits :: Word)
True
>>> complement (oneBits :: Word) == (zeroBits :: Word)
True

Note

The constraint on oneBits is arguably too strong. However, as some types (such as Natural) have undefined complement, this is the only safe choice.
Modifies a property so that it only will be tested once. Opposite of again.