Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [optional]

Use this tag for code that implements (or depends heavily on) a data type that can be empty or hold a value.

3 votes
1 answer
139 views

Partial specialization of class template with minimal code duplication

I have a class template that stores an std::optional<T>. A very reduced version of the class template looks like this: ...
joergbrech's user avatar
8 votes
3 answers
3k views

C++ std::optional implementation

Took a shot at implementing a subset of std::optional functionality. A lot of core features are there but some things like converting constructors, etc are missing ...
jdav22's user avatar
  • 361
-3 votes
1 answer
225 views

std::optional<std::size_t> correct values comparison [closed]

I need to compare two std::optional<std::size_t> variables, considering all possible cases(both std::nullopt or one of ...
Hardwired's user avatar
0 votes
2 answers
97 views

Java spring controller method to trigger e-mail verification procedure [closed]

For readability sake, is it better to use optionals or write my code in an iterative manner? Here's a route I'm working on, does this look readable do you? ...
user9132502's user avatar
5 votes
1 answer
531 views

Filtering an Option Result using a boolean Result in Rust

I'm trying to rewrite one of my pet projects in Rust, and when I was faced with the problem of filtering a Result<Option<T>, E> via a ...
Yalin Gunayer's user avatar
3 votes
1 answer
542 views

Rust idiomatic option handling

Is there a neater way of handling the option response from req.cookie() in this code block (line 3 onwards)? Id like to avoid the nested if statements, and multiple ...
richzilla's user avatar
  • 175
3 votes
3 answers
2k views

Concatenating optional strings in Scala

I have two optional strings, any of them can be None. I want to create their combination with a delimiter between them if they both exist. I expect to be able to come with a more concise and nicer ...
Suma's user avatar
  • 238
2 votes
2 answers
101 views

Treating Optional values

I have a situation when there could be and could not be values in database, which is why i return optional, so the response object that goes back to the UI could be different depending on the ...
Artjom's user avatar
  • 103
-1 votes
1 answer
3k views

Using Java Optional.ofNullable() instead of if/else or ternary conditional [closed]

I've recently reviewed code twice, from two different authors, where the author has cleverly used Thingy z = Optional.ofNullable(x).orElse(y) rather than using, say,...
Kirby's user avatar
  • 115
3 votes
2 answers
84 views

A Start button handler

I was told my code contains a lot of force unwrapping. I thought it's okay to do that if I am sure that the value operated won't be nil: ...
Anatolii Rudenko's user avatar
3 votes
1 answer
646 views

Updates or creates an entity based on if a value is present in an Optional

I need to get car info from a 3rd party web service and persist the data in my application DB. If my DB already has the car, I only update property values that may have changed. Otherwise, I create ...
James's user avatar
  • 299
2 votes
0 answers
57 views

Maybe with a structural pattern matching interface

With a reference implementation for PEP 622 now available in a Jupyter playground, I decided to copy over my favourite feature of Rust in full to Python. Note: this won't be released until Python 3.10 ...
Peilonrayz's user avatar
  • 43.4k
3 votes
1 answer
325 views

Unwrapping optionals for max of a 2D array in swift

I'm working in swift and I've got a custom class Array2D to handle fixed-width, two-dimensional arrays of integers. What I'm trying to do is write a simple, ideally-...
Zeph's user avatar
  • 133
4 votes
1 answer
2k views

C++ Optional Reference

Here is a good article on an optional reference type in C++. They discuss std::optional<T&>, but as that doesn't compile I have made my own. One purpose ...
Blue7's user avatar
  • 373
2 votes
1 answer
9k views

Best practice to initialize instance variables for a POJO when values are null

I am using Java 8. I haven't found another question that fits mine exactly, and I've come across some conflicting information on best practices with what I'm trying to do. I'm creating a POJO which ...
user355381's user avatar

15 30 50 per page