Top "Optional" questions

An immutable type that may contain a value or reference.

What's the most elegant way to combine optionals?

Here's what I've got so far: Optional<Foo> firstChoice = firstChoice(); Optional<Foo> secondChoice = secondChoice(); return Optional.…

java java-8 optional
Java 8 optional add return result only if optional.isPresent

I have a piece of code where an interface has an Optional return method and some of the classes that …

java java-8 optional null-check
Should I use Java8/Guava Optional for every method that may return null?

Optional is used to represent nullable object, Some uses of this class include As a method return type, as an …

java guava optional java-8
Swift: How to use for-in loop with an optional?

What's the proper way to use for-in loop with an optional? Right now I always perform an optional binding before …

swift2 optional for-in-loop
@OnClick array with optional ids (ButterKnife)

I have an activity that inflates a view when a web request finished. Some of the widgets of this view …

android onclick optional butterknife
What are Some and None?

I came across some output I don't understand using Vec::get. Here's the code: fn main() { let command = [('G', 'H'), (…

rust optional
Optional Int in Realm

I am trying to use an Optional Int in Realm and am getting an old error I think. Code dynamic …

swift int swift2 realm optional
How to use Java 8 Optionals, performing an action if all three are present?

I have some (simplified) code that uses Java Optionals: Optional<User> maybeTarget = userRepository.findById(id1); Optional<String&…

java java-8 optional
python regex match optional square brackets

I have the following strings: 1 "R J BRUCE & OTHERS V B J & W L A EDWARDS And Ors …

python regex optional brackets square-bracket
Getting Optional("") when trying to get value from KeyChain

When I try to get my keyChain value, it return a string containing: Optional("[thing in the KeyChain]") so, I …

swift nsstring keychain optional