Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [optional]

Optional is an immutable type that may contain a value or reference.

3
votes
1answer
61 views

Reference service for a cache

I'm using JDK 11. This is my code: ...
-2
votes
1answer
23 views

Change Kotlin optional-like style [closed]

I have next method in client fun authUser(loginRequest: LoginRequest): String? I need to implement next logic: check if user already exists - nothing to do, if ...
5
votes
2answers
95 views

C++ Maybe<T> implementation

In order to improve my understanding of C++ template meta-programming, SFINAE, references, and overall class design, I've tried to implement a Maybe<T> class ...
2
votes
1answer
76 views

Haskell/Yesod - Butchering use of MaybeT

The following is some code that is used to provide the frontend with certain parameters when rendering a form. The parameters are conditional based around what data is being changed, ...
3
votes
2answers
79 views

Conditionally display an Action depending on whether or not a player is connected

Is there a nicer way to write the maybeWhen portion of displayConnectionAction ? I want to conditionally display an ...
4
votes
0answers
60 views

Functional implementation of the Maybe Monad in JS [closed]

A while ago, I really wanted to have the Maybe Monad in my JS projects. I ended up trying to use Promises as a stand-in solution (using Promise.resolve as my unit, ...
7
votes
2answers
113 views

Class template for the encapsulation of datasheet specifications using optionals

A couple of years ago I wrote a pair of class templates to encapsulate specifications which have one or more of a minimum, typical, and/or maximum value, e.g. on a datasheet like this one for the 741 ...
3
votes
1answer
79 views

Java builder for user contact information, with optionals

I have this simple builder here: ...
2
votes
1answer
313 views

Fed Singleton struct class from plist

I have a plist file which has URLs in it and struct class is feeding from this plist. This struct class has static variable which I use to reach URLs in every part of the app. My question is that I'm ...
2
votes
1answer
35 views

Append /src to an Optional path

My method getProjectDir() will return an Optional which contains the path to the project directory, or an empty container: ...
1
vote
1answer
54 views

Handling multiple IO operations that return optional values

The following Haskell code reads a Pandoc document from the DB and then serves it to the user after making a transformation, after the first run it is stored in memory via ...
5
votes
1answer
564 views

Optional<T> implementation

I wrote an Optional<T> implementation in C++14 in order to support pre-C++17 compiler. Differences to ...
3
votes
1answer
133 views

Grab first successful pair from a list of maps

I have a function that parses geographic coordinates through a list of different providers. In this case I want to look up two addresses. The main problem of this question is - given a List of of ...
3
votes
2answers
130 views

Confirming whether a user is registered, using Optional class in Java 8

I start to learn Java 8 and I wondering is that kind of using Optional class is correct? ...
4
votes
0answers
112 views

deep_ptr<T>; a header-only, deep copying, value semantic smart pointer for optionally defined types

Edit: final revision here A couple days ago I posted a similar question here. Since then, I have refined the implementation a bit further, as the solution I had previously posited was a bit off ...
6
votes
1answer
154 views

Nullable<T>; header-only value semantics for forward declared types

Edit: I have refined the concept a bit further, and my new implementation can be found here Motivation: I found myself with class members of forward declared types in a header, such as: ...
5
votes
1answer
180 views

C++ Nullable template class

Today I implemented a C++11 template class which allows for Nullable types. The reason for this is that std::optional is not yet available, (I use C++11/14) and I wanted to practice a bit, so I ...
4
votes
1answer
1k views

Variant optional to return error string or value

I needed a class with more information than optionals give, I need to know why the optional is not valid in error states. I used a Boost variant for this. Since this will be wrapping almost all of my ...
10
votes
1answer
214 views

Implementing a Maybe for multidimensional data

The scenario is we're working with a REST endpoint that gives us nice JSON objects. We're using requests, and everything works wonderfully. But one day you notice that data you though was always being ...
4
votes
3answers
71 views

Concatenating multiple feedback messages

The goal is to build a String from a given set where Feedback is an interface and ...
6
votes
0answers
201 views

An optional_ref<T>

I omitted all free operators but the equality comparisons ones because of verbosity. I am glad about any comments and improvements. Motivation I know that optional references are equivalent to ...
3
votes
2answers
191 views

Use optional to check Null pointer exception

I currently have something like this: ...
1
vote
3answers
106 views

Select a list from a 2D list, take the last item from its nearest non empty left neighbour and put it at its head

I've just got into Haskell a few days ago and I love it. I'm looking for some pointers and best practices on how to organise and write Haskell code specifically when it comes to managing errors, which ...
3
votes
1answer
214 views

Maybe type implementation

This supposed to implement a Maybe type that can either hold a value T or "nothing". It's designed to work well with vectors (...
20
votes
3answers
2k views

Seamlessly migrating <experimental/optional> to <optional>

From this Stack Overflow answer, I learned that C++17 will have __has_include, which can [make] migrating from experimental to std almost seamless This still ...
15
votes
2answers
9k views

Filtering out empty Optionals

I want to convert my list of optional strings to a list of strings by getting rid of the empty Optionals. Is there a shorter version for achieving this than the ...
3
votes
3answers
2k views

Optional Consumer for ifNotPresent

As Optional have only ifPresent and not have another function to be run in false case so I did the below class for that, please check it and give me your feedback: ...
2
votes
2answers
4k views

C++ Optional Implementation

I haven't done much programming in C++, so I figured I'd try making an Optional class. I'm mainly concerned that I didn't follow good conventions or that I didn't ...
7
votes
1answer
1k views

An attempt at implementing Maybe in C++11

I gave a shot at implementing Maybe for C++ and a slight twist in my implementation is that it uses thread_local static instance ...
3
votes
1answer
286 views

Simple/Naive Implementation of Identity and Maybe Monad in Elixir

This is my first crack at a identity monad and a maybe monad in Elixir: ...
3
votes
2answers
331 views

Adding two values in a map, if they exist

My code looks like imperative style code. I want to make my code more functional. How I can rewrite my program so it become functional style code? ...