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.

option-type
-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]] = [...
PLUXVR's user avatar
  • 1
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 ...
dataman's user avatar
  • 125
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 ...
WowBow's user avatar
  • 7,433
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 (...
coderodde's user avatar
  • 929
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&...
DarkOwl's user avatar
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 = ...
christian wuensche's user avatar
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, ...
xvan's user avatar
  • 4,813
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 ...
dsillman2000's user avatar
  • 1,006
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 ...
k.liakos's user avatar
  • 659
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, ...
quaternionboy's user avatar
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!("...
Saroupille's user avatar
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
chadum's user avatar
  • 340
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 ...
Philip Adler's user avatar
  • 2,184
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((...
swift doubts's user avatar
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 ...
William Johnson's user avatar

15 30 50 per page
1
3 4
5
6 7
255