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.
option-type
3,815
questions
-1
votes
2
answers
88
views
How to convert/get std::optional<unsigned> variable value to unsigned/print in C++? [duplicate]
Is there a way to typecast optional unsigned variable to unsigned
#include <optional>
#include <iostream>
int main()
{
std::optional<unsigned> check = 200;
std::cout <&...
-2
votes
0
answers
26
views
how do I handle optional chaining with custom types in swift [closed]
I am working with a custom types in swift and I am running into issues with optional chaining.
I expected person.address?.street to safely handle the case where address is nil but I am getting a ...
1
vote
8
answers
134
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 ...
0
votes
1
answer
90
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(
...
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) {
...
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:
$...
-1
votes
1
answer
91
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 ...
-1
votes
1
answer
118
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 ...
-4
votes
2
answers
43
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....
0
votes
3
answers
69
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<...
0
votes
1
answer
30
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, ...
2
votes
2
answers
112
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 ...
2
votes
2
answers
76
views
Monad Map with two values in Java Functional Programming
Forgive me if this is a basic question in FP. Let's consider Optional monad. I know I can use map to transform an Optional to another Optional based on a function (which will be called if optional has ...
2
votes
1
answer
152
views
Chain an "if let" with a boolean expression
I am trying to chain an if let condition with a regular boolean condition.
if let Some(char_first_index) = char_info.first_index_in_string && !char_info.repeats_in_string
However, when I try ...
0
votes
0
answers
29
views
Show CSS in Option of Dropdownlist
how can I make the CSS part be displayed on the options in my dropdown list?
Here is a example what i want: codepen.io/luisaof392/pen/wvOjVGE
there you can actually recognize what I want
I'm new to ...