Skip to main content

rl_lang/docs/entries/tutorial/t2/
p_b12.rs

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static ADV_FILTERED_VIEWS: ConceptEntry = ConceptEntry {
4    name: "12. filtered views and stats",
5    summary: "filtered views and stats",
6    category: ConceptCategory::Tooling,
7    prerequisites: &[],
8    descriptions: &[
9        DescriptionEntry {
10            kind: DescriptionKind::Explanation,
11            title: None,
12            description: "list alone shows everything. extend it to accept an optional argument: 'list done' or 'list pending' shows only those tasks. the args string you already parse makes this straightforward",
13            examples: &[
14                "fn cmd_list(arr[arr[string]] tasks, string filter) {\n    dec arr[arr[string]] view = tasks\n\n    if (filter == \"done\")    { view = csv_filter_by(tasks, COL_STATUS, \"done\") }\n    if (filter == \"pending\") { view = csv_filter_by(tasks, COL_STATUS, \"pending\") }\n\n    if (len(view) == 0) {\n        println(\"no tasks\")\n        return\n    }\n    for task in view {\n        print_task(task)\n    }\n}",
15            ],
16            expected_output: &[],
17        },
18        DescriptionEntry {
19            kind: DescriptionKind::Explanation,
20            title: None,
21            description: "a stats command gives a useful summary. use arr_filter to count done vs pending, and format a clean report",
22            examples: &[
23                "fn cmd_stats(arr[arr[string]] tasks) {\n    dec int total   = len(tasks)\n    dec int done    = len(csv_filter_by(tasks, COL_STATUS, \"done\"))\n    dec int pending = total - done\n\n    println(format(\"total:   {}\", total))\n    println(format(\"done:    {}\", done))\n    println(format(\"pending: {}\", pending))\n}",
24            ],
25            expected_output: &[],
26        },
27        DescriptionEntry {
28            kind: DescriptionKind::Explanation,
29            title: None,
30            description: "exercise: update cmd_list to accept the filter argument and add cmd_stats. add 'stats' to the dispatch loop\n\nexpected output:\n  > list pending\n  [2] [pending] 2026-06-20  write tutorial\n  > stats\n  total:   2\n  done:    1\n  pending: 1",
31            examples: &[
32                "// updated dispatch for list:\n} else if (cmd == \"list\") {\n    cmd_list(tasks, args) // args is \"done\", \"pending\", or \"\"\n} else if (cmd == \"stats\") {\n    cmd_stats(tasks)\n}",
33            ],
34            expected_output: &[],
35        },
36    ],
37    pitfalls: &[],
38    related: &[],
39    related_stdlib: &[],
40    since: None,
41};