All Questions
Tagged with option-type dictionary
69
questions
-2
votes
1
answer
195
views
How to fix this force cast in swift
I am facing this below issue in my project, kindly help me to fix this issue.
Force Cast Violation: Force casts should be avoided. (force_cast)
var guestNetworks: [WanNetworks] {
for result in ...
-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]] = [...
-2
votes
2
answers
443
views
getting a Optional value in dictionary [closed]
Hi i am a newbie to Swift and i'm now trying to get data using JSON. i have completed getting a JSON data but have no idea how to get the value part using the key. The code below is the part i don't ...
-1
votes
2
answers
127
views
Optionals in Dictionary Arrays
I am working on some code and have received incorrect output and have been attempting to resolve it, I know its a pretty straightforward fix (or at least is should be) possibly casting it correctly or ...
0
votes
0
answers
96
views
Map on stream of Optionals type
I had a compiler problem which I was able to reduce to this example. This code
class A<T> {
Optional<Integer> op;
public Optional<Integer> getOp() {
return op;
}
...
0
votes
1
answer
722
views
How to create a hashmap that contains optional and when retreiving it gives me the value or Optional.empty but there are restrictions
How to create a hashmap that contains optional and when retreiving it gives me the value or Optional.empty? However, I am not allowed to check for null, Optional.empty() or use isPresent(), isEmpty(), ...
0
votes
2
answers
990
views
Java chaining map methods and using optional
I am using Java 8
method1() -> returns a Map<String,Map<String,Set<String>>>.
If I chain the method calls this way -> method1().get("A").get("B") a ...
0
votes
1
answer
200
views
Swiftui: how do you assign the value in a "String?" object to a "String" object?
Swiftui dictionaries have the feature that the value returned by using key access is always of type "optional". For example, a dictionary that has type String keys and type String values is ...
1
vote
2
answers
475
views
How to deal with a list of 'Maybe [values]' in Haskell?
I tryied to adapt some exercises of the excelent book "Land of Lisp" of Conrad Barski in order to learn Haskell. The idea is to make a simple text game engine.
Concretely I tried :
type Clau ...
-3
votes
2
answers
419
views
Swift dictionary subscript with optional values
Dears,
this is my code testable in a playground:
import Foundation
import UIKit
enum Error : Swift.Error, LocalizedError {
case failedTypeCastingUITableViewCell(name: String, type: Any.Type, ...
0
votes
0
answers
264
views
Pythonic way to create a dict with optional fields
I'd like to create a dict in a list comprehension that might not have some key. So far, I came up with this, but it looks rather ugly
{
"foo": 1,
<more fields>,
**({"bar": 2} if bar ...
3
votes
2
answers
860
views
Mapping a `Throwable?` to a `Result<Unit>` in Kotlin
What I'm trying to do, is map my Throwable? to a Result.failure or Result.success depending on its presence.
I figured this should be done with:
val a: Throwable? = Throwable()
val b = a?.let { ...
1
vote
1
answer
172
views
Can I do something not `transfrom` in `map` and `flatMap` function?
Is Map function of Optional in Swift just used to transform?
If I want do something just Optional has some value, Can I Use map function? if not, why?
According to apples examples, we used map ...
0
votes
0
answers
77
views
Java 8 return from Optional Map
I have a code segment as follows:
class MyObject{
Set<AnotherObject> mySet;
public Set<MyAnotherObject> getMySet(){
// getter code
}
}
if ( myObject.getMySet().isEmpty() ) {
...
-2
votes
1
answer
154
views
How to write a function which returns an optional array of strings from a dictionary variable?
I have a function that is written
func synonyms(for:) --> [String : [String?]]
and I want to make it so that it returns an array of optionals (Strings). I have a dictionary variable ([String : [...