Skip to content

New Observable value syntax (especially with Optionals) #4

@slazyk

Description

@slazyk

As originally described in the answer to #2, now that there is no possibility to define implicit conversions from Observable<T> to T, preferred way of getting the value out of the optional is via a postfix operator ^:

let y = doSomething(x^)

The main reason for it to be postfix is to allow easy chaining with similar syntax to optional chaining:

// .value is just too long in some cases
let y1 = obj.property.value.whatever.value.sthElse.value
// prefix requires parentheses
let y2 = ^(^(^obj.property).whatever).sthElse
// postfix allows nice chaining
let y3 = obj.property^.whatever^.sthElse^

However, for ^ to really be useful there is probably also need for ^! and ^?, because with optionals you now have to use parentheses, which kind of defeats the whole purpose:

let z = (me.friend^)!.lastName^

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