Skip to content

Commit 6be7e59

Browse files
committed
foi-toy: adding another test example
1 parent d87fe57 commit 6be7e59

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

foi-toy/test/test-5.foi

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
///
2+
NOTE: This code looks like the typical "async-await"
3+
style of code in JS, ported to Foi. In particular,
4+
this example shows off the ~<< do-comprehension
5+
syntax. The :: below are kind of like "await".
6+
///
7+
8+
9+
defn renderLargeOrders() ^Promise ~<< {
10+
def orders:: fetch("/all-orders");
11+
def largeOrders: orders ~filter (order) { order.total ?>= 100; };
12+
def customers:: all(
13+
largeOrders ~map (order) {
14+
fetch(\`"/customer/id/`order.custId`");
15+
}
16+
);
17+
def records: largeOrders ~map (order,idx) {
18+
< &order, customer: customers[idx] >;
19+
};
20+
\`"<ul>`
21+
(| ~fold records, "", (html,record) { html + \`"
22+
<li id=""order-`record.orderId`"">
23+
<span>Order #`record.orderId`</span>
24+
<span>Total: $`format(record.total)`</span>
25+
<span>Customer: `record.customer.name` (`record.custId`)</span>
26+
</li>
27+
"; } |)
28+
`</ul>";
29+
};
30+
31+
renderLargeOrders()
32+
~map (html) { document.body.innerHTML := html; };

0 commit comments

Comments
 (0)