on -package:numhask -package:ghc-lib-parser -package:gdp

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.
(op `on` f) x y = f x `op` f y

Examples

>>> sortBy (compare `on` length) [[0, 1, 2], [0, 1], [], [0]]
[[],[0],[0,1],[0,1,2]]
>>> ((+) `on` length) [1, 2, 3] [-1]
4
>>> ((,) `on` (*2)) 2 3
(4,6)

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.
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)
Build an attribute from a foreground color and a background color. Intended to be used infix.
An ON clause, useful to describe how two tables are related. Cross joins and tuple-joins do not need an on clause, but InnerJoin and the various outer joins do. Database.Esqueleto.Experimental in version 4.0.0.0 of the library. The Experimental module has a dramatically improved means for introducing tables and entities that provides more power and less potential for runtime errors. If you don't include an on clause (or include too many!) then a runtime exception will be thrown. As an example, consider this simple join:
select $
from $ \(foo `InnerJoin` bar) -> do
on (foo ^. FooId ==. bar ^. BarFooId)
...
We need to specify the clause for joining the two columns together. If we had this:
select $
from $ \(foo `CrossJoin` bar) -> do
...
Then we can safely omit the on clause, because the cross join will make pairs of all records possible. You can do multiple on clauses in a query. This query joins three tables, and has two on clauses:
select $
from $ \(foo `InnerJoin` bar `InnerJoin` baz) -> do
on (baz ^. BazId ==. bar ^. BarBazId)
on (foo ^. FooId ==. bar ^. BarFooId)
...
Old versions of esqueleto required that you provide the on clauses in reverse order. This restriction has been lifted - you can now provide on clauses in any order, and the SQL should work itself out. The above query is now totally equivalent to this:
select $
from $ \(foo `InnerJoin` bar `InnerJoin` baz) -> do
on (foo ^. FooId ==. bar ^. BarFooId)
on (baz ^. BazId ==. bar ^. BarBazId)
...
An ON clause that describes how two tables are related. This should be used as an infix operator after a JOIN. For example,
select $
from $ table @Person
`innerJoin` table @BlogPost
`on` (\(p :& bP) ->
p ^. PersonId ==. bP ^. BlogPostAuthorId)
(*) `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)
Add restriction to last join. Record type version.
Same as on. Arrow version. The result arrow is designed to be injected by local conditional flat-records.
Convenience function to register Events for Elements. Example usage.
on click element $ \_ -> ...
Convenience wrapper for onWithOptions defaultOptions.
let clickHandler = on "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]
Create a Binder that binds the action v to the input i.
Analogue of on
Shortcut for create, add and release:
releaseAction <- on element click $ do
w <- currentWindowUnchecked
alert w "I was clicked!"
-- remove click handler again
releaseAction
Handle a particular variant possibility. This is the main way to do case analysis (or deconstruct) a variant. Use it together with exhaustiveCase if you handle all possibilities, or defaultCase if you don't want to. Even though in many cases GHC is able to infer the types, it is a good idea to combine it with TypeApplications: Note that by doing so, GHC can infer the type of the function without problems:
>>> :{
example vary =
vary &
( Vary.on @Bool show
$ Vary.on @Int (\x -> show (x + 1))
$ Vary.defaultCase "other value"
)
:}
>>> :t example
example :: Vary (Bool : Int : l) -> String
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