Is there a Julia equivalent for this Python syntax

Lots of answers here, but unless I’m misunderstanding this is a classic situation for multiple dispatch:

check_id(id::Nothing) = nothing
check_id(id) = string(UUIDs.uuid4())[1:8]

Now just use check_id wherever you want. If id is nothing it returns nothing. If id is anything else it returns your UUIDs construct. This will run really fast and is type-stable.

The condition ? (x = x) : (x = y) construct on the other hand may result in the compiler being unable to infer the type of x until run-time which depending on how your code is structured could really slow things down.

2 Likes