Last active
December 27, 2015 13:09
-
-
Save niedbalski/7330899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Jorge Niedbalski <jnr@pyrosome.org> | |
class Query: | |
(c,d) = ([],[]) | |
def __init__(self): | |
pass | |
def a(self, d): | |
self.d.append(d) | |
return self | |
def f(self, k, v): | |
self.c.append((k, v)) | |
return self | |
def g(self): | |
for entry in self.d: | |
cc = [] | |
for k,v in self.c: | |
try: | |
cc.append(entry[k] == v) | |
except KeyError: | |
pass | |
if any(cc): | |
yield entry | |
def f(): | |
persons = Query() \ | |
.a({'name': 'tester', 'address': 'test avenue 99'})\ | |
.a({'name': 'tester1', 'address': 'test avenue 100'})\ | |
.a({'name': 'tester2', 'address': 'test avenue 101'})\ | |
.f('name', 'tester').g() | |
for person in persons: | |
print person | |
f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment