Functional Weave
Code in Rust

todo.list@1.1.0

impl/python/toggle_all.py

672 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from dataclasses import replace
from typing import List, Sequence

from .todo_item import Todo  ← from todo.item ^1.0.0 · built alongside by fune
from .todo_list_add_todo import require_utc_now  ← addTodo, another function of this group · built into the same file, even by a slim install
from .todo_list_toggle_all_mode import toggle_all_mode  ← toggleAllMode, another function of this group · built into the same file, even by a slim install
from .todo_list_toggle_todo import complete_todo, require_today  ← toggleTodo, another function of this group · built into the same file, even by a slim install


def toggle_all(todos: Sequence[Todo], now: str, today: str) -> List[Todo]:
    """Complete every open todo as toggle_todo would, or reopen all once none is open."""
    require_utc_now(now)
    require_today(today)
    if toggle_all_mode(todos) == "complete":
        return [t if t.done else complete_todo(t, now, today) for t in todos]
    return [replace(t, done=False, completed_at=None) for t in todos]