-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor out some panics in CedarProto #557
Conversation
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
@@ -61,6 +61,12 @@ def map {α β} (f : α → β) : Qualified α → Qualified β | |||
| optional a => optional (f a) | |||
| required a => required (f a) | |||
|
|||
def transpose {α ε} : Qualified (Except ε α) → Except ε (Qualified α) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm uncertain if we need this function here. Intuitively,
let attrs ← attrs.toList.mapM λ (k,v) => do
let v ← v.map ProtoType.toCedarType |>.transpose
.ok (k, v)
can be written like
let attrs ← attrs.toList.mapM λ (k,q) => do
let t ← ProtoType.toCedarType q.getType
.ok (k, q.map ∘ Function.const t)
Or we can write this function as q.getType.map fun t1 => q.map ∘ Function.const t1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntactically correct version:
def transpose {α ε} (q : Qualified (Except ε α)) : Except ε (Qualified α) :=
q.getType.map ((q.map ∘ Function.const _) ·)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I acknowledge you're correct, but I find that harder to read; anyone else have thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current definition seems more readable to me. I don't know what q.getType
or Function.const
mean so I guess some familiarity with those methods is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -61,6 +61,12 @@ def map {α β} (f : α → β) : Qualified α → Qualified β | |||
| optional a => optional (f a) | |||
| required a => required (f a) | |||
|
|||
def transpose {α ε} : Qualified (Except ε α) → Except ε (Qualified α) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current definition seems more readable to me. I don't know what q.getType
or Function.const
mean so I guess some familiarity with those methods is needed.
Refactors out some panics in CedarProto. Specifically, the Protobuf parser now gracefully fails (rather than panicking) when encountering:
ip()
ordecimal()
argument that fails to parse