All Questions
Tagged with option-type monads
105
questions
2
votes
2
answers
82
views
Monad Map with two values in Java Functional Programming
Forgive me if this is a basic question in FP. Let's consider Optional monad. I know I can use map to transform an Optional to another Optional based on a function (which will be called if optional has ...
1
vote
0
answers
59
views
Pure functional way of creating a std::optional counterpart
I'm working on a pure functional library for c++ and I met a design problem. I was creating the monad Option. This is my implementation
namespace ns {
struct _NoValue_t {};
const _NoValue_t ...
0
votes
0
answers
39
views
TypeScript + Property 'nothing' does not exist on type '<T>(x: T)
I'm trying to hone my Typescript monad skills, so I have created a version of the Maybe monad that technically seems to be working at this point, but Typescript is complaining that Property 'nothing' ...
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 ...
1
vote
1
answer
54
views
Designing an example `return` and `>>=` for int option addition
Just to exercise the concepts of a monad, I am trying to write an OCaml program with a return and >>= function, which makes sense for the int option type. In particular, it seems to me that ...
2
votes
1
answer
516
views
What is the advantage of Option/Maybe Monad over Functor?
I understand the advantage of IO monad and List Monad over Functor, however, I don't understand the advantage of Option/Maybe Monad over Functor.
Is that simply the integration of types of the ...
10
votes
7
answers
783
views
Functional composition of Optionals
I have 2 Optionals (or Maybe objects) that I would like to combine so that I get the following results:
|| first operand
second ++-------------+-------------
...
5
votes
1
answer
4k
views
How is the Maybe monad useful in TypeScript?
I’m struggling to understand the value of having a Maybe type in TypeScript. I’m trying to make sense of the code example from this article about implementing your own Maybe type in TypeScript:
enum ...
1
vote
1
answer
222
views
What is the idiomatic (and fast) way of treating the empty list/Seq as failure in a short-circuiting operation?
I have a situation where I am using functions to model rule applications, with each function returning the actions it would take when applied, or, if the rule cannot be applied, the empty list. I have ...
1
vote
1
answer
147
views
Haskell (Maybe, x, Maybe y, Maybe z) -> Maybe (x,y,z)
I have a set of Haskell IO bound calls that return Maybe Z, Maybe Y, Maybe Z, where X /= Y /= Z.
I would like a function that returns Just (X,Y,Z) where ALL are Just n, or else Nothing.
A naive ...
4
votes
3
answers
574
views
Obtaining a Bool out of [Maybe Bool] which is guaranteed to contain at least one Just
I have an input list of type [Maybe SomeType] and a predicate p of type SomeType -> Bool, and I want to answer the question "Does the predicate p hold for all SomeTypes that happen to be in ...
0
votes
1
answer
555
views
The "Maybe" monad and simple "try/catch" solution
I have a question about using the "Maybe" monad in object-oriented languages.
Namely, the "spirit" of using the monad says instead of writing code like:
return getUser(id).group....
7
votes
1
answer
255
views
Reduce nestedness when using successive Either/Maybe
This is probably a very basic Haskell question, but let's assume the following function signatures
-- helper functions
getWeatherInfo :: Day -> IO (Either WeatherException WeatherInfo)
craftQuery ::...
2
votes
1
answer
223
views
How to make std::optional a run-time monad with Hana?
The type hana::optional represents an
Optional value whose optional-ness is known at compile-time
and it models, among others, the concept of Monad. Since it is a compile-time optional, the question ...
2
votes
1
answer
224
views
Haskell extract hostname from URLType
I'm using Network.URL and importing a URL from a String:
url_type $ fromJust $ importURL "https://google.com/"
Absolute (Host {protocol = HTTP True, host = "google.com", port = ...