Skip to main content

Questions tagged [option-type]

The option type or maybe type is a polymorphic type that represents encapsulation of an optional value where one side encapsulates the value, and other side represents the absence of the value (None, Nothing, etc). This tag is adequate for questions about `Option` in Scala, `Optional` in Java and Swift, `std::optional` in C++ and similar types.

-4 votes
2 answers
250 views

Why `emplace()` without arguments returns 0 when I try to read an `std::optional<unsigned>` variable? [duplicate]

Below is the example code snippet: #include <optional> #include <iostream> int main() { std::optional<unsigned> check = 200; std::cout << check << std::endl; ...
0 votes
2 answers
1k views

Bootstrap 5 is not working after I using Select2 dropdown

The Select2 functionality is functioning correctly. However, there is an issue with Bootstrap, after using Select2, Bootstrap is not working anymore. I am using Bootstrap 5.3.The picture show that the ...
-2 votes
0 answers
11 views

The automatic selection method of two drop-down fields linked together with JavaScript [closed]

When the site is reloaded, the drop-down boxes will be filled automatically And after the first drop-down field is filled, the second drop-down field will be filled automatically For example, the ...
3 votes
3 answers
795 views

Iterating over std::optional

I tried to iterate over an std::optional: for (auto x : optionalValue) { ... } With the expectation of it doing nothing if optionalValue is empty but doing one iteration if there is a value ...
-2 votes
0 answers
37 views

Why Java shows strange characters when print a OptionalDouble? [duplicate]

I declared a OptionalDouble vector, and when the program print this give me strange characters instead of the vector values: [[Ljava.util.OptionalDouble;@37bba4006. [[Ljava.util.OptionalDouble;@...
168 votes
11 answers
205k views

Default optional parameter in Swift function

When I set firstThing to default nil this will work, without the default value of nil I get a error that there is a missing parameter when calling the function. By typing Int? I thought it made it ...
0 votes
2 answers
59 views

unwrap or evalulate to false in rust

I have encountered several cases similar this: if let Some(x) = formula_chars.peek() { if x.is_lowercase() { todo!() } } where I would like an expression to evaluate to false if an ...
-4 votes
0 answers
75 views

std::optional is not available though I'm using G++9 [closed]

`error: ‘optional’ in namespace ‘std’ does not name a template type ** | std::optional<double> ; | ^~~~~~~~ ‘std::optional’ is only available from C++17 onwards ** | std::...
667 votes
28 answers
332k views

Why should Java 8's Optional not be used in arguments

I've read on many Web sites Optional should be used as a return type only, and not used in method arguments. I'm struggling to find a logical reason why. For example I have a piece of logic which ...
1 vote
2 answers
6k views

JSON schema validation of optional fields using Golang

Golang JSON schema validation libraries validate that required fields on the schema are present in the service request/response. I need to validate that any field in a service request or response ...
0 votes
1 answer
134 views

How to call an API and select correct optional from update method in spring MVC

I have been following online tutorials for MVC but have hit a snag with updating. Have used a updateStudent() method in the controller and pass in the id, but inside the updateStudent() I have a lot ...
21 votes
2 answers
15k views

How do I convert a list of Option<T> to a list of T when T cannot be copied? [duplicate]

How do I take a Vec<Option<T>>, where T cannot be copied, and unwrap all the Some values? I run into an error in the map step. I'm happy to move ownership of the original list and "throw ...
1 vote
1 answer
1k views

Regex to match array of strings and optional array of strings

I am making a syntax highlighting service for guitar chord sheets. I am trying to highlight the guitar chords and not the lyrics. However, it gets complicated when guitar chords can be comprised of ...
182 votes
6 answers
88k views

Swift optional escaping closure parameter

Given: typealias Action = () -> () var action: Action = { } func doStuff(stuff: String, completion: @escaping Action) { print(stuff) action = completion completion() } func ...
14 votes
2 answers
11k views

How to safely unwrap optional variables in dart?

I couldn't find a way to safely unwrap an optional variable as we do in swift var myString: String? if let myString = myString { print(myString) // myString is a string } or in Kotlin var myString: ...

15 30 50 per page
1
2 3 4 5
255