New: Portable Classes

@jshaffstall, you’re right that the little code sample I provided searches through all rows of a search iterator. However, it’s entirely possible to use Portable Classes to build your own lazy iterator! The simplest way, if you’re OK with sending the Data Tables search iterator to the client, is to send it as a private attribute of a Portable Class.

Here’s an example that wraps a search iterator, and dynamically instantiates objects:

class PotatoSack:
  def __init__(self):
    self._search = app_tables.potatoes.search()

  def __iter__(self):
    return iter((Potato(row['weight'], row['temperature']) for row in self._search))

Or you could build a lazy iterator entirely yourself, implementing __iter__ and __next__ and calling a server function that gives you a “page” of results at a time. (This is what Owen’s library does.)


If you were using capabilities, you’d want the PotatoSack to have a Capability on, say, ['potatoes'] (or a narrower capability permitting access only to a particular subset), and then hand each Potato a narrowed capability on, say, ['potatoes', 'potato_253'].

2 Likes