{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a19301a",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Iterators are often used to construct\n",
    "\n",
    "    producer/consumer pipelines\n",
    "    \n",
    "\"\"\"\n",
    "\n",
    "# Producer/consumer construct:\n",
    "\n",
    "# Producer\n",
    "def follow(f):\n",
    "    ...\n",
    "    while True:\n",
    "        ...\n",
    "        yield line        # Produces value in `line` below\n",
    "        ...\n",
    "\n",
    "# Consumer\n",
    "for line in follow(f):    # Consumes value from `yield` above\n",
    "    ...\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10c07b50",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Here's a typical producre/consumer pipeline:\n",
    "\n",
    "    producer → processing → processing → consumer\n",
    "    \n",
    "The producer is typically a generator. \n",
    "(Although it could also be a list of some other sequence.)\n",
    "Producers use \"yield\" to feeds data into the pipeline.\n",
    "\n",
    "Consumer is a for-loop. \n",
    "It gets items and does something with them.\n",
    "\n",
    "A \"processing\" node is a combine producer/consumer node.\n",
    "Intermediate processing stages simultaneously consume and produce items. \n",
    "They might modify the data stream. They can also filter (discarding items).\n",
    "\"\"\"\n",
    "\n",
    "# How to setup Producer/processing/consumer pipeline in Python\n",
    "\n",
    "def producer():\n",
    "    ...\n",
    "    yield item\n",
    "    ...\n",
    "\n",
    "\n",
    "def consumer(s)\n",
    "    for item in s:\n",
    "        ...\n",
    "\n",
    "def processing(s):\n",
    "    for item in s:\n",
    "        ...\n",
    "        yield newitem\n",
    "        ...\n",
    "        \n",
    "# Code to setup the pipeline\n",
    "a = producer()\n",
    "b = processing(a)\n",
    "c = consumer(b)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
