Void as a variable type

About Monkey 2 Forums Monkey 2 Development Void as a variable type

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  Samah 2 years, 10 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1186

    Samah
    Participant

    This may sound like a strange request, but I have a use case where I want to be able to declare a variable or argument as “Void”, and assign a “Void” value to it. Specifically, it’s a generic class and function that passes its type through to a closure, in which Void is a sensible parameter.

    [/crayon]

    Of course this won’t compile, because you can’t define Foo.value as Void, nor can you define the argument to the closure as Void.

    Swift allows you to define variables as Void, but the only valid value is (), an empty tuple, which essentially means “nothing”. Not even nil or Null.

    If not, I guess there’ll be a requirement to always have a return type, and exactly one argument. Also, there is method to the madness, and the nested closures are required. 😉

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.