asserting a dyn to a map type

35 views
Skip to first unread message

Dan Kortschak

unread,
Jun 25, 2023, 8:16:29 PM6/25/23
to CEL Go Discussion Forum
I have a situation where the activation is a dyn, but in some cases I
know that it is a <map<string,dyn>>. I have extensions that overload on
the known type and walk into the map with a path, and cannot use the
dyn type (this could be relaxed, but I would rather not just for this).
Is there a way to assert/coerce with potential of failure to the map
type? I don't see this anywhere.

What I am able to do instead of `val.walk("a.b.c")` is `{"val":
val}.walk("val.a.b.c")` which does work. Am I missing something?

thanks
Dan

Tristan Swadell

unread,
Jun 26, 2023, 2:45:03 PM6/26/23
to Dan Kortschak, CEL Go Discussion Forum
Hi Dan,

There are no map() type assertions, but you could write `type(val) == map ? val.walk("...") : {"val": val}.walk("...")`

I'm not sure if that helps, but maybe so.

-Tristan

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/770ff9e143a5dc8b99b8d021218b5f9b47aae7ee.camel%40kortschak.io.

Dan Kortschak

unread,
Jun 27, 2023, 2:47:54 AM6/27/23
to cel-go-...@googlegroups.com
On Mon, 2023-06-26 at 11:44 -0700, 'Tristan Swadell' via CEL Go
Discussion Forum wrote:
> Hi Dan,
>
> There are no map() type assertions, but you could write `type(val) ==
> map ? val.walk("...") : {"val": val}.walk("...")`
>
> I'm not sure if that helps, but maybe so.
>
> -Tristan

Thanks, Tristan. Clarification always helps.

Dan

Reply all
Reply to author
Forward
0 new messages