Top "Optional" questions

An immutable type that may contain a value or reference.

Providing a default value for an Optional in Swift?

The idiom for dealing with optionals in Swift seems excessively verbose, if all you want to do is provide a …

swift optional
Avoid NoSuchElementException with Stream

I have the following Stream: Stream<T> stream = stream(); T result = stream.filter(t -> { double x = …

java java-8 java-stream optional
Django modelform NOT required field

I have a form like this: class My_Form(ModelForm): class Meta: model = My_Class fields = ('first_name', 'last_name' , …

django django-forms optional django-models
Checking the value of an Optional Bool

When I want to check if an Optional Bool is true, doing this doesn't work: var boolean : Bool? = false if …

swift boolean optional
Using multiple let-as within a if-statement in Swift

I'm unwrapping two values from a dictionary and before using them I have to cast them and test for the …

if-statement swift optional
Java 8 extract first key from matching value in a Map

Suppose I have a map of given name, surname pairs and I want to find the given name of the …

java lambda java-8 java-stream optional
Why create "Implicitly Unwrapped Optionals", since that implies you know there's a value?

Why would you create a "Implicitly Unwrapped Optional" vs creating just a regular variable or constant? If you know that …

swift design-patterns optional
Should Java 8 getters return optional type?

Optional type introduced in Java 8 is a new thing for many developers. Is a getter method returning Optional<Foo&…

java java-8 nullable optional
How does @RequestParam in Spring handle Guava's Optional?

@RequestMapping(value = "/contact.html", method = RequestMethod.POST) public final ModelAndView contact( @RequestParam(value = "name", required = false) Optional<String> …

spring spring-mvc guava nullable optional
Swift optional escaping closure parameter

Given: typealias Action = () -> () var action: Action = { } func doStuff(stuff: String, completion: @escaping Action) { print(stuff) action = completion completion() } …

swift function closures optional