# Exercise: Combining List Operations
#
# The real power emerges when you chain operations.
#
# Example: Get total length of long words
#   "a be see deep" " " string.split
#   [ string.length 2 i.> ] list.filter   # keeps "see" "deep"
#   0 [ string.length i.+ ] list.fold  # 7 (3 + 4)
#
# HIGHER-ORDER INSIGHT:
# Each operation is a building block. Combine them to express
# complex transformations clearly. This is the essence of
# functional programming with higher-order functions.
#
# Your task: From the list "apple banana apricot cherry":
#   1. Filter to keep only words that start with 'a'
#         → "apple" and "apricot"
#   2. Fold their lengths into a single total
#         → 5 (apple) + 7 (apricot) = 12
# So the final answer is 12 — the total CHARACTER COUNT of the
# matching words, not the number of words.
#
# When done, delete the marker line below.

# I AM NOT DONE

: count-a-word-chars ( List -- Int )
    # Your code here
    # Step 1: filter words starting with 'a' using [ 0 string.char-at 97 i.= ]
    #         (97 is ASCII for 'a')
    # Step 2: fold with [ string.length i.+ ], starting from 0
    drop 0
;

: test-combine ( -- )
    "apple banana apricot cherry" " " string.split count-a-word-chars
    # Do not edit below this line
    12 test.assert-eq   # "apple" (5) + "apricot" (7) = 12
;
