codegen-2 2.8.2__tar.gz → 2.9.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.9.0
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -254,7 +254,7 @@ class ExprTernary(Expr):
254
254
  return f"{self.true_expr.to_python()} if {self.condition.to_python()} else {self.false_expr.to_python()}"
255
255
 
256
256
  def to_typescript(self):
257
- return f"{self.true_expr.to_typescript()} ? {self.condition.to_typescript()} : {self.false_expr.to_typescript()}"
257
+ return f"{self.condition.to_typescript()} ? {self.true_expr.to_typescript()} : {self.false_expr.to_typescript()}"
258
258
 
259
259
 
260
260
  class PredefinedFn:
@@ -361,15 +361,26 @@ class PredefinedFn:
361
361
  class map_list(Expr):
362
362
  collection: Expr
363
363
  func: Expr
364
-
365
- def __init__(self, collection: Expr, func: Callable[[ExprIdent], Expr]):
364
+ filter: Optional[Expr] = None
365
+
366
+ def __init__(
367
+ self,
368
+ collection: Expr,
369
+ func: Callable[[ExprIdent], Expr],
370
+ filter: Optional[Callable[[ExprIdent], Expr]] = None,
371
+ ):
366
372
  self.collection = collection
367
373
  self.func = func(ExprIdent("_x"))
374
+ self.filter = filter(ExprIdent("_x")) if filter is not None else None
368
375
 
369
376
  def to_python(self):
377
+ if self.filter is not None:
378
+ return f"[{self.func.to_python()} for _x in {self.collection.to_python()} if {self.filter.to_python()}]"
370
379
  return f"[{self.func.to_python()} for _x in {self.collection.to_python()}]"
371
380
 
372
381
  def to_typescript(self):
382
+ if self.filter is not None:
383
+ return f"{self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()})"
373
384
  return f"{self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()})"
374
385
 
375
386
  @dataclass
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.8.2"
3
+ version = "2.9.0"
4
4
  description = "Meta-programming"
5
5
  authors = ["Binh Vu <binh@toan2.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes