Functional Python

  • Recapping: Functional programming maintains no external state and provides data flow synchronisation in the language
  • This maps very nicely to the UNIX filter idea. Data flows in and out, with no side affects to the system
  • Consider the following script to add numbers, one per line:
    #!/usr/bin/python import sys print sum(int(line) for line in sys.stdin)
  • This is both efficient and scalable
    • Efficient because as much iteration as possible is done in compiled code
    • Scalable because only as much memory is used as required for efficiency
  • seq 100 | add