# ── Generated by Nexa Transpiler ──────────────────────────────
# This file was auto-generated from a .nexa source file.
# Do not edit directly — regenerate with: nexa compile <file>
# ─────────────────────────────────────────────────────────────
from __future__ import annotations
import asyncio, math, json, os, random, functools, time as _time
import sys as _sys
_sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_sys.path.insert(0, os.path.expanduser('~/.nexa/packages'))
from nexa_lang.builtins import BUILTINS

# ── Nexa runtime stubs ───────────────────────────────────────
_nexa_modules = {}
def _nexa_opt_access(obj, attr):
    if obj is None: return None
    if isinstance(obj, dict): return obj.get(attr)
    return getattr(obj, attr, None)

def _nexa_invoke_method(obj, method, *args, **kwargs):
    if isinstance(obj, list):
        if method == 'push': return obj.append(*args, **kwargs)
        if method == 'join': return (args[0] if args else '').join(str(x) for x in obj)
        if method == 'map': return list(map(args[0], obj))
        if method == 'filter': return list(filter(args[0], obj))
        if method == 'reduce': return functools.reduce(args[0], obj, *args[1:]) if len(args) > 1 else functools.reduce(args[0], obj)
    if isinstance(obj, dict) and method == 'keys': return list(obj.keys())
    if isinstance(obj, dict) and method == 'values': return list(obj.values())
    return getattr(obj, method)(*args, **kwargs)

task = BUILTINS['task']
print('=== Nexa v13 Showcase ===')
print('\n--- 1. Functional Array Methods ---')
numbers = [1, 2, 3, 4, 5]
print('Numbers:', numbers)
def sq(x):
    return (x * x)
squares = list(map(sq, numbers))
print('Squares (map):', squares)
def is_even(x):
    return ((x % 2) == 0)
evens = list(filter(is_even, numbers))
print('Evens (filter):', evens)
def sum_it(acc, x):
    return (acc + x)
sum_val = functools.reduce(sum_it, numbers, 0)
print('Sum (reduce):', sum_val)
print('\n--- 2. String Validation Methods ---')
fname = 'photo_2024.jpg'
print('File:', fname)
print("Starts with 'photo'?:", _nexa_invoke_method(fname, 'startswith', 'photo'))
print("Starts with 'video'?:", _nexa_invoke_method(fname, 'startswith', 'video'))
print("Ends with '.jpg'?:", _nexa_invoke_method(fname, 'endswith', '.jpg'))
print('\n--- 3. Task Concurrency (asyncio gather) ---')
async def fetch_data(id):
    print('Fetching data for ID', id, '...')
    await _nexa_invoke_method(task, 'sleep', 0.5)
    return ('Data_' + str(id))
async def main():
    print('Launching tasks...')
    results = await _nexa_invoke_method(task, 'gather', [fetch_data(1), fetch_data(2), fetch_data(3)])
    print('Gathered Results:', results)
asyncio.run(main())
print('\n✅ All Nexa v13 features successfully verified!')
