option-type Questions

3

Is it possibile to have an java.util.Optional which is evaluated only if needed? I need to pass an Optional to a method (of an API that I cannot change), and this method may or may not make use th...
Gulch asked 1/6, 2017 at 14:59

3

Solved

For example: private String test(Optional myOptional) { myOptional.ifPresent(() -> return "1"); return "0"; } so when I call test(myOptional) it will return "1";
Alimentary asked 3/8, 2017 at 12:45

2

Solved

How can I serialize a class (with boost::serialization) that contains a boost::optional? I.e. the following code will give an error when instantiated. error C2039: 'serialize' : is not a member...
Placia asked 26/9, 2014 at 14:27

3

Solved

Say I have a list like: [Nothing, Just 1, Nothing, Just 2] I want to get the first Just (non-error) value; in this case, it's Just 1. The only thing I can think of is: firstJust xs = case filte...
Dinnie asked 4/4, 2016 at 19:13

7

Solved

In Java 8, I have a variable, holding an optional boolean. I want an action to be executed, if the optional is not empty, and the contained boolean is true. I am dreaming about something like ifP...
Repatriate asked 16/10, 2017 at 8:55

5

I have a code fragment that I want to make more concise yet readable using Java 8 features like lambdas/streams etc. Basically, there is a list of items and each item has a list of errors. If ther...
Gardia asked 19/1, 2019 at 11:54

3

Solved

I am trying to use an Optional Int in Realm and am getting an old error I think. Code dynamic var reps: Int? = nil Error 'Property cannot be marked dynamic because its type cannot be represen...
Guthrie asked 26/10, 2015 at 21:58

6

Solved

Why does this throw a java.lang.NullPointerException? List<String> strings = new ArrayList<>(); strings.add(null); strings.add("test"); String firstString = strings.stream() ...
Multiplicity asked 8/9, 2015 at 20:36

5

Solved

So after some reading I've seen that if (optional.isPresent()) { //do smth } is not the preferred way to use Optional (http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.ht...
Wellchosen asked 20/1, 2016 at 14:5

6

Solved

I love that optionals are in the Java standard library now. But there is one basic problem that I keep running into that I haven't figured out how to solve in the best way (easiest to read and unde...
Decimalize asked 27/6, 2016 at 20:28

2

Solved

I am trying to make this conversion (Option<Option<String>> to Option<Option<&str>>) possible, but I still failed after trying many methods including using .map. I know ...
Zone asked 6/12, 2023 at 1:24

25

Is there a way to check strings for nil and "" in Swift? In Rails, I can use blank() to check. I currently have this, but it seems overkill: if stringA? != nil { if !stringA!.isEmpty { ...bla...
Cytologist asked 1/4, 2015 at 2:41

11

Solved

I have been reading about Optionals in Swift, and I have seen examples where if let is used to check if an Optional holds a value, and in case it does – do something with the unwrapped value. Howe...
Oversubscribe asked 27/8, 2015 at 18:23

3

I have an async function that returns an optional String. func traverse(file:URL, for string:String) async throws -> String? { ... } I want to run this function and if nil, run it with differen...
Fjord asked 2/8, 2021 at 16:30

11

Solved

Looking for a way to chain optionals so that the first one that is present is returned. If none are present Optional.empty() should be returned. Assuming I have several methods like this: Optiona...
Suffuse asked 14/2, 2015 at 10:32

2

Solved

I am getting started with fp-ts lib and was wondering what is the advantage of using Option type over typescript's default notion of optional values represented by question mark ? operator?
Inhale asked 27/3, 2020 at 12:42

10

Solved

I am trying to understand the difference between the Optional<T>.orElse() and Optional<T>.orElseGet() methods. The description for the orElse() method is "Return the value if present,...
Anabiosis asked 16/10, 2015 at 12:5

3

Solved

I am very new to Apache Spark. I would actually like to focus on basic Spark API specification and want to understand and write some programs using Spark API. I have written a java program using Ap...
Roveover asked 5/2, 2015 at 7:47

2

Solved

There are already 2 similar questions of this type here on SO but none of the answers seem to work. PHPDoc doesn't seem to recognize optional parameters in my functions as optional, for example: ...
Cath asked 18/11, 2012 at 15:4

2

Suppose I am writing a function that takes a bunch of strings and filters out the "bad" ones. The function then returns some strings, but there is a chance that all the strings are filter...
Nedranedrah asked 18/7, 2023 at 1:12

8

Solved

In the following sample program, is there any way I could avoid having to define map2? fn map2<T, U, V, F: Fn(T, U) -> V>(f: F, a: Option<T>, b: Option<U>) -> Option<V&g...
Scincoid asked 18/11, 2015 at 12:2

7

Solved

Optional type introduced in Java 8 is a new thing for many developers. Is a getter method returning Optional<Foo> type in place of the classic Foo a good practice? Assume that the value can ...
Panslavism asked 12/10, 2014 at 17:30

4

On my first post I am using Inteliij and I have problem with my project. I was make project in Spring Boot. All works fine on this computer. Today when I copy this project from my computer to anoth...
Keef asked 16/1, 2023 at 10:0

8

Solved

I need a function that its parameter is an object, and if I leave it empty it will load default values. something like: function loadMap(args) { //args is an object and its optional //this is w...
Plenum asked 1/1, 2015 at 23:55

4

I was wondering why in Haskell (and FP in general) functors such as the Maybe functor are defined as data Maybe a = Nothing | Just a Instead of simply data Maybe a = Nothing | a The second option...
Minh asked 31/5, 2023 at 17:49

© 2022 - 2024 — McMap. All rights reserved.