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,820
questions
-1
votes
1
answer
45
views
meaning of this code: return self.desk[number]![alpha]
please help me understand this part of the code. Why is ! located between two brackets []![] in this expression: self.desk[number]![alpha]?
class GameDesk {
var desk : [Int: [String: Chessman]] = [...
0
votes
3
answers
112
views
How best to populate a variable using Optional?
I'm using an optional ID here but I don't like having to declare TWO variables to receive the data. What is a more concise way to accomplish this without having to declare an extra OptionalOrg ...
0
votes
0
answers
90
views
Mockito: Boolean cannot be returned by findById() findById() should return Optional
I've the following test case I am testing and this line is causing an exception:
when(actorService.actorExists(actorId)).thenReturn(true)
Boolean cannot be returned by findById() findById() should ...
1
vote
0
answers
89
views
Own mapMaybe does not parse
So I have the following type annotation in Haskell:
mapMaybe :: (a -> b) -> Maybe a -> Maybe b
And it is defined as follows:
mapMaybe _ Nothing = Nothing
mapMaybe f (Just x) = Just (head (...
0
votes
0
answers
31
views
Clear nested option html form field
Do someone know how to clear option nested field in form with f.e. jQuery or simple js?
My form is quite simple (in table):
<table width="100%">
<tr>
<td colspan="2&...
0
votes
1
answer
102
views
TypeScript, keep type information of initial generic union type
According to the following code, is it possible to tell TypeScript to check the "origin" type of a generic union type, even the generic is "lost"?
const justSymbol: unique symbol = ...
1
vote
1
answer
109
views
Roslyn: generate method optional parameters from reflected interface
Given SomeInterfaceType that has a method with optional parameters:
interface SomeInterface
{
void SomeMethod(int a = 1, string c = "foo",
SomeType e = default, ...
0
votes
0
answers
65
views
How to design a Python class that inherits from a type determined at instantiation?
I'm trying to design a Python class called Try, which takes one or more Option[T] types as constructor arguments. Try should inherit all of its attributes and functions from the first non-None value ...
1
vote
2
answers
2k
views
How to make Jackson deserialize explicit null to Optional.EMPTY, but not to serialize empty Optional as null
Assuming I have a POJO like this:
public static class Test {
private Optional<String> something;
}
And a Jackson mapper like this:
var OBJECT_MAPPER = JsonMapper.builder()
.addModule(new ...
1
vote
1
answer
729
views
TextField binding to optional number
struct ContentView: View {
@State private var data: Double?
var body: some View {
VStack {
TextField("",
value: $data,
...
1
vote
2
answers
328
views
Memory overhead of `Option` in Rust is not constant [duplicate]
Using the following snippet
use std::mem;
fn main() {
println!("size Option(bool): {} ({})", mem::size_of::<Option<bool>>(), mem::size_of::<bool>());
println!("...
0
votes
2
answers
32
views
Is there a more functional way to transform an Option value of None?
I have an Option[Int] and I want to transform None to Some(0).
I know I can do this with pattern matching. Is there anything more direct or simple?
thanks
1
vote
3
answers
132
views
Accumulate a Function Over a List of Monads (Maybe)
I'm learning Haskell as a way of getting to grips with a new programming paradigm. I'm getting hung up on a specific, probably basic, issue. While I'm finding lots of documentation and other stack ...
0
votes
1
answer
131
views
Initializer for conditional binding must have Optional type, not 'Float' Error in swift
Given:
var conv_factor: String?
var standard_rate_in_usd: Double?
now I need a Float value
var floatVal: Float?
if let priceVal = Float(indexData.standard_rate_in_usd!),
let convVal = Float((...
0
votes
0
answers
206
views
Combining Optional.ofNullable() null check in java
I am doing a null check using Optional.ofNullable() for an API response where all the fields are optional (for lack of a better word), but we want to map the ones that are present, which may differ on ...