codegen-2 2.8.2__tar.gz → 2.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: codegen-2
3
- Version: 2.8.2
3
+ Version: 2.10.0
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -235,6 +235,28 @@ class ExprNegation(Expr):
235
235
  return f"not {self.expr.to_wrapped_python()}"
236
236
 
237
237
 
238
+ @dataclass
239
+ class ExprLogicalAnd(Expr):
240
+ terms: Sequence[Expr]
241
+
242
+ def to_python(self):
243
+ return f" and ".join([term.to_python() for term in self.terms])
244
+
245
+ def to_typescript(self):
246
+ return f" && ".join([term.to_typescript() for term in self.terms])
247
+
248
+
249
+ @dataclass
250
+ class ExprLogicalOr(Expr):
251
+ terms: Sequence[Expr]
252
+
253
+ def to_python(self):
254
+ return f" or ".join([term.to_python() for term in self.terms])
255
+
256
+ def to_typescript(self):
257
+ return f" || ".join([term.to_typescript() for term in self.terms])
258
+
259
+
238
260
  @dataclass
239
261
  class ExprDivision(Expr):
240
262
  left: Expr
@@ -254,7 +276,7 @@ class ExprTernary(Expr):
254
276
  return f"{self.true_expr.to_python()} if {self.condition.to_python()} else {self.false_expr.to_python()}"
255
277
 
256
278
  def to_typescript(self):
257
- return f"{self.true_expr.to_typescript()} ? {self.condition.to_typescript()} : {self.false_expr.to_typescript()}"
279
+ return f"{self.condition.to_typescript()} ? {self.true_expr.to_typescript()} : {self.false_expr.to_typescript()}"
258
280
 
259
281
 
260
282
  class PredefinedFn:
@@ -361,15 +383,26 @@ class PredefinedFn:
361
383
  class map_list(Expr):
362
384
  collection: Expr
363
385
  func: Expr
364
-
365
- def __init__(self, collection: Expr, func: Callable[[ExprIdent], Expr]):
386
+ filter: Optional[Expr] = None
387
+
388
+ def __init__(
389
+ self,
390
+ collection: Expr,
391
+ func: Callable[[ExprIdent], Expr],
392
+ filter: Optional[Callable[[ExprIdent], Expr]] = None,
393
+ ):
366
394
  self.collection = collection
367
395
  self.func = func(ExprIdent("_x"))
396
+ self.filter = filter(ExprIdent("_x")) if filter is not None else None
368
397
 
369
398
  def to_python(self):
399
+ if self.filter is not None:
400
+ return f"[{self.func.to_python()} for _x in {self.collection.to_python()} if {self.filter.to_python()}]"
370
401
  return f"[{self.func.to_python()} for _x in {self.collection.to_python()}]"
371
402
 
372
403
  def to_typescript(self):
404
+ if self.filter is not None:
405
+ return f"{self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()})"
373
406
  return f"{self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()})"
374
407
 
375
408
  @dataclass
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.8.2"
3
+ version = "2.10.0"
4
4
  description = "Meta-programming"
5
5
  authors = ["Binh Vu <binh@toan2.com>"]
6
6
  license = "MIT"
File without changes
File without changes