Hey!

I am just wondering if there is any syntactic sugar for shortening the
following code segment

[code]
Element? nsource = ElementFactory.make("filesrc", "file-source");
if (nsource == null) { printError(); return; }
Element source = (Element)nsource;
[/code]


To me, it seems like a common pattern to convert a nullable type to a
non-nullable type.  If such a shortcut does not exist, perhaps it would
be a good idea to add a "conditional cast" operator

Four examples of a possible "conditional cast":

Element a = ElementFactory.make("filesrc", "file-source") or
some_code_block(); // Returns an Element


Element b = ElementFactory.make("filesrc", "file-source") or () =>
{/*...*/};


Element c = ElementFactory.make("filesrc", "file-source") or throw new
Foo.Bar();


Element d = ElementFactory.make("networksrc", "net-source") or
ElementFactory.make("filesrc", "file-source") or throw new Foo.Bar();


(Inspired by: http://tinyurl.com/yc7mgxj)


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to