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.

-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 ...
behzad egder's user avatar
-2 votes
0 answers
36 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;@...
Bujakiewicz Franco's user avatar
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 ...
Pioneer_11's user avatar
  • 1,034
-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::...
o_o's user avatar
  • 1
-3 votes
2 answers
242 views

Why does `emplace()` without arguments return 0 and can we use it to read a `std::optional<unsigned>` variable? [duplicate]

Is there a way to typecast an optional unsigned std::optional<unsigned> variable to unsigned? #include <optional> #include <iostream> int main() { std::optional<unsigned> ...
thirdeye's user avatar
  • 306
1 vote
8 answers
137 views

Decent idiom for initializing an optional to either null or a value?

Motivation With C++ having gotten optional's (in C++17), it is now common to want to write the equivalent of: If a condition holds, initialize my variable with some expression; and if the condition ...
einpoklum's user avatar
  • 127k
0 votes
1 answer
92 views

Optional's orElse() executed even when object is present [duplicate]

I've encountered an unexpected behavior while using the Optional API in Java. Session session = sessionService .getSessionById(id) .orElse( ...
Souhaib's user avatar
  • 119
1 vote
0 answers
22 views

Why Optional lambda replace with method reference Causing NullPointerException [duplicate]

There is a A Class class A { private String str; public void setStr(String str) { this.str = str; } } this method works fine; public static void main(String[] args) { ...
周亿进's user avatar
0 votes
0 answers
18 views

fetching rows from db that are selected by dropbar

guys i wrote a dropdown bar connected to a db, but i couldnt make the content of the table thats fetched from db only specified by the option i chose in drop bar, how can i fix this here's my code: $...
ty track's user avatar
-1 votes
1 answer
92 views

How to force non-optional type (for array element) on compile time in Swift? [closed]

struct MyStruct { @ArrayOfNonOptionalElements var arr: [SomeNonOptionalType] } where @ArrayOfNonOptionalElements is a propertyWrapper. So, how to force non-optionality for the type inside? Is it ...
Roman's user avatar
  • 1,485
-1 votes
1 answer
122 views

Generate a type from a Java DTO type with many fields being null and have all getters as Optional<T>

I am currently working with a Java DTO class (written by others) that has almost 300 fields where many of these end up being null. What I see in the codebase are lots of null checks and more recently ...
Leon's user avatar
  • 528
-4 votes
2 answers
45 views

How to pass a positional argument from one function to *args in another function in python

I have a two scripts and a custom email module with two Functions that works. But I need a single generic function in the custom email module used by both the scripts . Script 1 import email_module....
Ash_05's user avatar
  • 1
0 votes
3 answers
71 views

Springboot: How to get an entity optional property and check null?

I have a service in Springboot and I want to get an optional entity and to check if is not null to do something after. User repository class public interface UserRepository extends JpaRepository<...
obela06's user avatar
  • 325
0 votes
1 answer
31 views

Typescript Maybe, error about null not being covered

I don't know how to get rid of this error, and I don't know why it talks about null. Shouldn't the seo?.breadcrumbs || [] already cover the case where breadcrumbs is null? However in the Intro Propos, ...
JorgeeFG's user avatar
  • 5,843
2 votes
2 answers
116 views

Optional.ifPresent throws NPE when action is null AND optional not present

Why does this throw a NullPointerException? The docs for Java 8 state that: "If a value is present, invoke the specified consumer with the value, otherwise do nothing." public static ...
pecks's user avatar
  • 340

15 30 50 per page
1
2 3 4 5
255