Welcome to the Community, and thanks for sharing this!
Would you be willing to kindly provide some additional details to help the Community understand how you're using this code snippet and what your use case was? Otherwise, if this was intended as a reply to another post, please feel free to send me a direct message, and I’ll be happy to help move it to the appropriate place!