Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active December 15, 2015 20:18
Show Gist options
  • Save kachayev/5317194 to your computer and use it in GitHub Desktop.
Save kachayev/5317194 to your computer and use it in GitHub Desktop.
# python 2.7+
class Node(object):
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def __iter__(self):
yield self.value
for n in self.left:
yield n
for n in self.right:
yield n
# python 3.3+
class Node:
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def __iter__(self):
yield self.value
yield from self.left
yield from self.right
# fn.py
from fn import Stream
class Node:
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def __iter__(self):
# compare to:
# return (self.value #:: self.left #:: self.right)
return iter(Stream(self.value) << self.left << self.right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment