Advertisement
homer512

Python F# pipe

Jul 27th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3.  
  4. import math
  5.  
  6.  
  7. class pipe(object):
  8.     def __init__(self, start_value):
  9.         self.value = start_value
  10.  
  11.     def __or__(self, function):
  12.         self.value = function(self.value)
  13.         return self
  14.  
  15.  
  16. def main():
  17.     average = lambda sequence: math.fsum(sequence) / len(sequence)
  18.     pipe(range(1, 10)) | average | 'The average is {0}'.format | print
  19.  
  20.  
  21. if __name__ == '__main__':
  22.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement