All Questions
Tagged with option-type functional-programming
114
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 ...
1
vote
1
answer
44
views
Why typescript cannot refer the type in my example correctly?
Considering the code for Option ADT as below (pretty similar to fp-ts Option):
export type Option<A> = Some<A> | None
export interface Some<A> {
_tag: 'Some'
value: A
}
export ...
0
votes
1
answer
91
views
Implementing the Option Functor in Julia - while maintaining type stability
First off, I have created the following attempt at an Option-type in Julia:
# building an Option-type
abstract type MyNothing end
struct None{T} <: MyNothing end
Option = Union{Some{T},None{T}} ...
5
votes
4
answers
249
views
In Functional Programming, why the Maybe functor is not defined as data Maybe a = Nothing | a?
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 ...
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 (...
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 = ...
0
votes
1
answer
203
views
Questions about the design of the Optional class
I have been trying to figure why some decisions have been made regarding the design of java.util.Optional. The issues I had with it were:
I felt it's inelegant that java would wrap Optional instances ...
0
votes
1
answer
146
views
Java: How to throw an exception in optional ifPresent using method reference or use a runnable in ifPresent
I would like to simulate an optional .ifPresentThrow() to use somenthing like:
.ifPresent(MyException::go)
and not use:
.ifPresent(e -> {
throw new MyException();
})
so I created my class with ...
0
votes
2
answers
530
views
What am i doing wrong in this Java optional - orElse statement
List<String> list =
Arrays.asList("TEST1", "TEST2", "TEST3");
final String finalStr =
Optional.ofNullable(list.stream()
.filter(s -> s....
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 ++-------------+-------------
...
1
vote
2
answers
60
views
How to Write a Change Detector with Two Optionals in Functional Java?
Is there a functional way to write a change reporter for two optional variables?
The code is meant to detect value changes when moving from the value in Optional A to the value in Optional B with one ...
1
vote
1
answer
564
views
Optional variable take action based on its value
I have a method which takes an Optional parameter and returns a list. I'll populate the list based on whether the Optional parameter is empty or not. What's the most accepted/standard way if any to ...
1
vote
2
answers
2k
views
Using Optional's ifPresentOrElse method but return promise instead of void
I'm trying to get my around a current issue I'm facing.
I have a function that returns an Optional type (an object with a few properties)
One of the properties is an url that might be present or not. ...
0
votes
1
answer
139
views
What is This More General Almost-Traversal Operation
Trying to wrap my mind around traversals - or maybe something slightly different, in this case.
I understand a traversal to be an operation that performs an applicative operation (or effect) over a ...