-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinline_pushdown.knot
More file actions
55 lines (48 loc) · 1.5 KB
/
Copy pathinline_pushdown.knot
File metadata and controls
55 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Cases that should push down to SQL after full inlining.
with {
type Employee = {name: Text, dept: Text, salary: Int 1}
*employees : [Employee]
-- Helper functions used inside lambda bodies.
isHighEarner (\e -> e.salary > 75)
salaryOf (\e -> e.salary)
inDept (\name e -> e.dept == name)
-- 1. filter where the predicate body calls a helper function.
case1 (do
emps <- *employees
yield (emps |> base.filter (\e -> isHighEarner e)))
-- 2. minOn where the projection lambda body calls a helper.
case2 (do
emps <- *employees
yield (emps |> base.minOn (\e -> salaryOf e)))
-- 3. filter then count, with predicate via helper.
case3 (do
emps <- *employees
with {filtered (emps |> base.filter (\e -> isHighEarner e))} yield (base.count filtered))
-- 4. filter using a curried helper.
case4 (do
emps <- *employees
yield (base.filter (inDept "Eng") emps))
-- 5. countWhere with helper-built predicate.
case5 (do
emps <- *employees
yield (base.countWhere (\e -> isHighEarner e) emps))
}
(do
replace *employees = [
{name "Alice" dept "Eng" salary 90}
{name "Bob" dept "Eng" salary 80}
{name "Carol" dept "Sales" salary 70}
{name "Dave" dept "Sales" salary 60}
{name "Eve" dept "Eng" salary 100}
]
c1 <- case1
base.println ("case1: " ++ base.show c1)
c2 <- case2
base.println ("case2: " ++ base.show c2)
c3 <- case3
base.println ("case3: " ++ base.show c3)
c4 <- case4
base.println ("case4: " ++ base.show c4)
c5 <- case5
base.println ("case5: " ++ base.show c5)
yield {})