tailcallhq / tailcall

High Performance GraphQL Runtime
https://tailcall.run
Apache License 2.0
1.28k stars 244 forks source link

feat: adding try_valid macro #2309

Closed shashitnak closed 3 months ago

shashitnak commented 3 months ago

Summary:
Adding a macro try_valid which works similar to how ? operator works for Result and Option types.

Example usage

fn square_if_valid(x: Valid<i32, String>) -> Valid<i32, String> {
  let x = try_valid!(x); // returns early if the value is an Errror
  Valid::succeed(x*x)
}

Build & Testing:

Checklist:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.80%. Comparing base (7b76052) to head (8e65168).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2309 +/- ## ========================================== + Coverage 85.79% 85.80% +0.01% ========================================== Files 236 236 Lines 22248 22264 +16 ========================================== + Hits 19088 19104 +16 Misses 3160 3160 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tusharmath commented 3 months ago

Closing this PR because I am not sure this is adding much value over what we already have.