Skip to content

Preemptive Unwrap #2

@kj6dev

Description

@kj6dev

Maybe ???

In a case where there is a function taking parameters from an optional value that is then doing internal checks for optionality and then return nil itself, why not do some sort of soft unwrap with a postfix operator (or something). Something like "unwrap or return nil".

In a place where it would be
parameter: if let myStruct { foo(myStruct.propA, myStruct.propB) } else { nil }
it could be
parameter: myStruct ??? foo(myStruct.propA, myStruct.propB) }

I can't think of a way where the signature could stay as this

parameter: if let myStruct { foo(myStruct?.propA, myStruct?.propB) } else { nil }

but somehow let that function immediately return nil if myStruct is nil

Maybe a wrapper that modifies a parameter or parameter type?

Similar but nicer than myStruct != nil ? foo(myStruct!.propA, myStruct!.propB) : nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions