Skip to content

Lazy evaluation of ternary operator's true/false cases #46

@nighthawk

Description

@nighthawk

I've set up a bunch of expression functions and am hitting an issue where the ternary operator might check a condition and if that condition isn't met, the true part throws an error. Say I have a date: Date variable and a format/2 function that expects a Date and String and throws an error if the first parameter is not a Date. If I then use that in an expression like date != nil ? format(date, "yyyy-MM-dd") : "None" when date = nil, it'll throw that error rather than returning "None".

I could adjust my functions to not throw errors and return nil instead, but then I'm losing useful information when I use them elsewhere. And I'd have to change most functions to always accept nil for every parameter. Not ideal.

I'm wondering if it's possible to have the ternary operator evaluate the true/false cases lazily and, in particular, only evaluate the necessary part.

Or is there another possibility to address this? Feedback appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions