http icon indicating copy to clipboard operation
http copied to clipboard

[Feature] Pattern Matching extensions

Open baweaver opened this issue 4 years ago • 0 comments

I'd like to propose adding pattern matching to some of the core classes of http, primarily deconstruct_keys, to allow for matching against things like Responses and Requests.

Consider:

response in {
  status: 200..299,
  body: /Header I want/
}

case response
in { status: 200..299, body: } then Success(body)
in { status: 300.., body: } then Failure(body)
else Failure('unknown')
end

This is just a theoretical example and may not be 100% accurate to the API, but I wanted to run things by the core team before implementing this as it ends up being a decent amount of additional code.

It should be noted that adding the interfaces (deconstruct and deconstruct_keys) will be backward compatible, but testing it with pattern matching will not be.

baweaver avatar Jan 19 '21 03:01 baweaver