-
-
Save kustosz/49e1c588de4c1513cf91b18dd6342c15 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
class Value: | |
ColumnRef Text | |
ValText Text | |
ValReal Real | |
Operation Text (List Value) | |
def toJSON: case self of | |
ColumnRef n: JSON.empty . insert "column" n | |
ValText t: t.toJSON | |
ValReal r: r.toJSON | |
Operation n args: JSON.empty.insert "operation" n . insert "arguments" args | |
def startsWith t: Operation "startsWith" [self, t.toLQueryValue] | |
def matches regex: Operation "matches" [self, regex.toLQueryValue] | |
def > that: Predicate "gt" [self, that.toLQueryValue] | |
def == that: Predicate "eq" [self, that.toLQueryValue] | |
def < that: Predicate "lt" [self, that.toLQueryValue] | |
def + that: Operation "plus" [self, that.toLQueryValue] | |
def - that: Operation "minus" [self, that.toLQueryValue] | |
def * that: Operation "times" [self, that.toLQueryValue] | |
def / that: Operation "divide" [self, that.toLQueryValue] | |
def negate: Operation "negate" [self] | |
def toLQueryValue self: self | |
class Predicate: | |
Predicate Text (List Value) | |
Boolean Text (List Predicate) | |
def and that: Boolean "and" [self, that] | |
def or that: Boolean "or" [self, that] | |
def not: Boolean "not" [self] | |
def toJSON: case self of | |
Predicate t args: JSON.empty.insert "predicate" t . insert "arguments" args | |
Boolean t args: JSON.empty.insert "boolean" t . insert "arguments" args | |
class Table: | |
def at name: ColumnRef name | |
class Dataframe: | |
def filter f: | |
pred = f Table | |
compiled = compileLQueryPredicate pred | |
runFilterLQuery compiled self | |
def each f: | |
mapper = f Table | |
compiled = compileLQueryMod mapper | |
runEachLQuery compiled self | |
def main: | |
myFrame . filter (row: row.at "income" > 0 && (row.at "income" / row.at "familySize") < row.at "expensesPerFamilyMember" * 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment