Functional Python

  • Here I present a more complete script that illustrates how one can use functional python from the linux command line
  • Using existing functional units within the script
    • seq 100 | funcpy add
  • Using user provided expressions
    • This shows the flexibility of interpretation (scripts) over compilation
    • Supported by the following construct
      func=lambda x: eval(code)
    • echo -e "1234\n433" | funcpy "hex(int(x))[2:]" #transform nums
    • echo "1,2,3" | funcpy "int(x.split(',')[1])**2" #single column
    • echo "1,2,3" | funcpy "add(int(i) for i in x.split(','))" #reiterate
    • echo -e "1\n2\n3" | funcpy "int(x)%2 and x or None" #filter
    • echo "12341234.432142" | funcpy '"%g" % float(x)' #formatting
    • ls | funcpy --import=base64 "base64.encodestring(x)[:-1]" #modules
      • This can be used to integrate larger (user) functions into funcpy