You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manipulating and querying ASTs is inherently a complex problem. Often, we need to perform consecutive checks for children's properties, including their type and value. This leads to repetitive, not-so-readable code. Here's an example of such code:
This second approach is more declarative and makes it easier to grasp the expected node structure. Moreover, we can select parts of the matched node with the P.select() function and make use of it in the following callback function.
Acceptance Criteria
Initially, it would suffice to implement a match(node) function that accepts two additional methods:
with(structure, callback | value) - matches with given object structure, and returns either the value or the callback's returned value when(function, callback | value) - matches with the given matching function, and returns either the value or the callback's returned value
The text was updated successfully, but these errors were encountered:
Description
Manipulating and querying ASTs is inherently a complex problem. Often, we need to perform consecutive checks for children's properties, including their type and value. This leads to repetitive, not-so-readable code. Here's an example of such code:
And here's how this could be replaced with TS-Pattern
This second approach is more declarative and makes it easier to grasp the expected node structure. Moreover, we can select parts of the matched node with the
P.select()
function and make use of it in the following callback function.Acceptance Criteria
Initially, it would suffice to implement a
match(node)
function that accepts two additional methods:with(structure, callback | value)
- matches with given object structure, and returns either the value or the callback's returned valuewhen(function, callback | value)
- matches with the given matching function, and returns either the value or the callback's returned valueThe text was updated successfully, but these errors were encountered: