{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ch11-title",
   "metadata": {},
   "source": [
    "# Functional Programming"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch11-overview",
   "metadata": {},
   "source": [
    "Functional programming is a style of writing programs as transformations from inputs to outputs.\n",
    "\n",
    "- Pure functions and side effects\n",
    "- Immutable data and returned values\n",
    "- Functions as values\n",
    "- Comprehensions, lambdas, and higher-order functions\n",
    "- Decorators, recursion, context managers, and `functools`\n",
    "\n",
    "Python is not a purely functional language, but it includes functional tools that help you write concise, reusable, and testable code.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1100-video",
   "metadata": {},
   "source": [
    "<h2>Chapter Video</h2>\n",
    "\n",
    "This overview introduces the idea that functions are values that can be assigned, passed, and returned.\n",
    "\n",
    "```{raw} html\n",
    "<iframe width=\"100%\" height=\"400\" src=\"https://www.youtube-nocookie.com/embed/kr0mpwqttM0\" title=\"Programming Terms: First-Class Functions\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen referrerpolicy=\"strict-origin-when-cross-origin\"></iframe>\n",
    "```\n",
    "\n",
    "> *[Programming Terms: First-Class Functions (15:28)](https://youtube.com/watch?v=kr0mpwqttM0) by Corey Schafer*\n",
    ">\n",
    "> Hosted on YouTube; property of its original creator, embedded here for educational reference only."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch11-goals",
   "metadata": {},
   "source": [
    "<h2>Learning Objectives</h2>\n",
    "\n",
    "By the end of this chapter, you will be able to:\n",
    "\n",
    "1. Identify pure functions and avoid unnecessary side effects\n",
    "2. Use immutability by returning new values instead of mutating existing objects\n",
    "3. Treat functions as first-class values that can be passed to and returned from other functions\n",
    "4. Use lambda functions with `map()`, `filter()`, and `sorted()`\n",
    "5. Build decorators, recursive functions, context managers, and selected `functools` utilities\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch11-flow",
   "metadata": {},
   "source": [
    "<h2>Chapter Flow</h2>\n",
    "\n",
    "```{container} chapter-flow\n",
    "1. {doc}`1001-func-prog`\n",
    "2. {doc}`1002-func-practice`\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch10-glossary",
   "metadata": {},
   "source": [
    "<h2>Glossary</h2>\n",
    "\n",
    "| # | Term | Explanation |\n",
    "|---:|---|---|\n",
    "| 1 | Functional programming | A programming style that emphasizes functions, expressions, and limited mutation. |\n",
    "| 2 | Pure function | A function whose output depends only on its inputs and that has no side effects. |\n",
    "| 3 | Side effect | A change or interaction outside a function's returned value, such as printing or mutating data. |\n",
    "| 4 | Immutability | The practice of using values that are not changed after creation. |\n",
    "| 5 | First-class function | A function that can be stored, passed as an argument, or returned like other values. |\n",
    "| 6 | Higher-order function | A function that accepts another function as an argument or returns a function. |\n",
    "| 7 | Lambda function | A small anonymous function written with the `lambda` keyword. |\n",
    "| 8 | Map | A pattern that transforms each item in a collection. |\n",
    "| 9 | Filter | A pattern that keeps only items that satisfy a condition. |\n",
    "| 10 | Reduce | A pattern that combines many values into one result. |\n",
    "| 11 | Decorator | A function that wraps another function to extend or change its behavior. |\n",
    "| 12 | Comprehension | A compact expression for building a collection from an iterable. |\n",
    "| 13 | Recursion | A technique where a function calls itself on a smaller version of a problem. |\n",
    "| 14 | Base case | The stopping condition in a recursive function. |\n",
    "| 15 | Recursive case | The part of a recursive function that calls the function again. |\n",
    "| 16 | Context manager | An object that manages setup and cleanup around a `with` block. |\n",
    "| 17 | `functools` | A standard-library module with tools for functional programming patterns. |\n",
    "| 18 | Partial function | A function with some arguments pre-filled, often created with `functools.partial`. |\n",
    "| 19 | Cached result | A saved function result returned immediately when the same arguments are used again. |\n",
    "| 20 | `lru_cache` | A `functools` decorator that memoizes recent function calls. |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1100-slides",
   "metadata": {},
   "source": [
    "<h2><a href=\"overview.html\" target=\"_blank\" style=\"color: var(--pst-color-link, #176de8);\">Chapter Overview Slides</a></h2>"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
