Copyright | © Thor Michael Støre, 2015 |
---|---|
License | GPL v2 without "any later version" clause |
Maintainer | thormichael át gmâïl døt cöm |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Predicates and aggregates useful to relational querying. These are not part of the relational algebra but are useful in relational queries in restriction predicates, and extension and summarization expressions. It also has great utility in non-relational queries, such as when performing aggregations.
- (&=) :: a -> (a -> Bool) -> Bool
- plusminus :: (Ord a, Num a) => a -> a -> a -> Bool
- (+-) :: (Ord a, Num a) => a -> a -> a -> Bool
- (±) :: (Ord a, Num a) => a -> a -> a -> Bool
- between :: Ord a => a -> (a, a) -> Bool
- (>=<=) :: Ord a => a -> a -> a -> Bool
- (≥≤) :: Ord a => a -> a -> a -> Bool
- xBetween :: Ord a => a -> (a, a) -> Bool
- (><) :: Ord a => a -> a -> a -> Bool
- (>=<) :: Ord a => a -> a -> a -> Bool
- (≥<) :: Ord a => a -> a -> a -> Bool
- (><=) :: Ord a => a -> a -> a -> Bool
- (>≤) :: Ord a => a -> a -> a -> Bool
- (≤) :: Ord a => a -> a -> Bool
- (≥) :: Ord a => a -> a -> Bool
- (≠) :: Eq a => a -> a -> Bool
- avg :: (Fractional a, Real a1) => [a1] -> a
- minx :: Ord a => [a] -> a -> a
- maxx :: Ord a => [a] -> a -> a
Predicates
(&=) :: a -> (a -> Bool) -> Bool infix 5 Source
Reverse predicate application. As "Data.Function.&", the reverse function application operator, but restricted to a boolean result.
(±) :: (Ord a, Num a) => a -> a -> a -> Bool infix 7 Source
>>>
10 &= 9 ± 3
True>>>
rPrint$ p ∣ (\[pun|weight|] -> weight &= 9 ± 3)
┌─────┬───────┬───────┬────────┬────────┐ │ pno │ pName │ color │ weight │ city │ ╞═════╪═══════╪═══════╪════════╪════════╡ │ P1 │ Nut │ Red │ 12 % 1 │ London │ │ P5 │ Cam │ Blue │ 12 % 1 │ Paris │ └─────┴───────┴───────┴────────┴────────┘
(≥≤) :: Ord a => a -> a -> a -> Bool Source
>>>
5 &= 5 ≥≤ 9
True>>>
rPrint$ p ∣ (\[pun|weight|] -> weight &= 11 ≥≤ 14)
┌─────┬───────┬───────┬────────┬────────┐ │ pno │ pName │ color │ weight │ city │ ╞═════╪═══════╪═══════╪════════╪════════╡ │ P1 │ Nut │ Red │ 12 % 1 │ London │ │ P4 │ Screw │ Red │ 14 % 1 │ London │ │ P5 │ Cam │ Blue │ 12 % 1 │ Paris │ └─────┴───────┴───────┴────────┴────────┘
(><) :: Ord a => a -> a -> a -> Bool Source
>>>
5 &= 5 >< 9
False>>>
rPrint$ p ∣ (\[pun|weight|] -> weight &= 11 >< 14)
┌─────┬───────┬───────┬────────┬────────┐ │ pno │ pName │ color │ weight │ city │ ╞═════╪═══════╪═══════╪════════╪════════╡ │ P1 │ Nut │ Red │ 12 % 1 │ London │ │ P5 │ Cam │ Blue │ 12 % 1 │ Paris │ └─────┴───────┴───────┴────────┴────────┘
Aggregates
avg :: (Fractional a, Real a1) => [a1] -> a Source
Average of a list of values
>>>
let _qtys a = Label .=. a :: Tagged "qtys" Double
>>>
pt$ group sp (rHdr (pno,qty)) (_qtys . avg . agg qty)
┌────────────────────┬───────────────┐ │ qtys :: Double │ sno :: String │ ╞════════════════════╪═══════════════╡ │ 200.0 │ S3 │ │ 216.66666666666666 │ S1 │ │ 300.0 │ S4 │ │ 350.0 │ S2 │ └────────────────────┴───────────────┘
Note the explicit type in the definition of _qtys
; it is neccessary to provide a specific type for pt
to format it as a table, even when an expression would otherwise be correct without this. The following would blow up if prefixed with "pt$":
>>>
group sp (rHdr (pno,qty)) ((qtys .=.) . avg . agg qty)
fromList [Record{qtys=200.0,sno="S3"},Record{qtys=216.66666666666666,sno="S1"},Record{qtys=300.0,sno="S4"},Record{qtys=350.0,sno="S2"}]
minx :: Ord a => [a] -> a -> a Source
Minimum of several values, defaulting to the second argument if there are no elements.
>>>
pt$ group sp (rHdr (pno,qty)) ((qtys .=.) . (`minx` 0) . agg qty)
┌─────────────────┬───────────────┐ │ qtys :: Integer │ sno :: String │ ╞═════════════════╪═══════════════╡ │ 100 │ S1 │ │ 200 │ S3 │ │ 200 │ S4 │ │ 300 │ S2 │ └─────────────────┴───────────────┘
maxx :: Ord a => [a] -> a -> a Source
Maximum of several values, defaulting to the second argument if there are no elements
>>>
pt$ group sp (rHdr (pno,qty)) ((qtys .=.) . (`maxx` 0) . agg qty)
┌─────────────────┬───────────────┐ │ qtys :: Integer │ sno :: String │ ╞═════════════════╪═══════════════╡ │ 200 │ S3 │ │ 400 │ S1 │ │ 400 │ S2 │ │ 400 │ S4 │ └─────────────────┴───────────────┘