Missing "join" method on ADTs
See original GitHub issueBased on my understanding of many of the ADTs, as described here, I think crocks is missing join
.
Here is a simplified use case (I realize I could create this function with more of the functional building-blocks Crocks supplies):
// { } -> String -> Either(Error String, a)
const getData = payload => {
return field => {
const data = payload[field]
// hmmm..
if (!data) {
return Left(new Error(`Cannot get field "${data}"`))
} else {
return Right(data)
}
}
}
const result = Either(
getData({ 10: 100, 'dogs': 'cats' })
)
.ap(Right('dogs'))
console.log(result)
// Right Right 'cats'
The problem is that the result is a Right
inside a Right
.
I’d like to be able to do this:
const result = Either(
getData({ 10: 100, 'dogs': 'cats' })
)
.ap(Right('dogs'))
.join()
console.log(result)
// Right 'cats'
Am I missing something? Is there a different way to use ap
that wouldn’t create nested types?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Reading 12: Defining ADTs with Interfaces, Generics, Enums, and ...
define ADTs using classes, interfaces, generics, and enumerations ... An interface in TypeScript is a list of method signatures without method bodies.
Read more >As Black women go missing in Kansas City, Black community ...
After the Kansas City Police Department denied community claims of women missing along Prospect Avenue, Black community members are creating ...
Read more >Why Can't I Join an Amazon Household?
You might not be able to join an Amazon Household because: The Amazon Household has reached its member limit: An Amazon Household can...
Read more >Relationships & Social Skills - CHADD
Unfortunately, as adults, they often realize “something” is missing but are never quite sure what that “something” may be. Social acceptance can be...
Read more >Your Child Is Missing a Permanent Tooth
It's so common that up to 20% of all adults are missing at least one ... These methods are not always interchangeable, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have strong memories of missing this function, and this looks useful for sure. Since we’re prefixing
m
to most array-colliding functions likemconcat
,mreduce
et al, we could even considermjoin
for consistency’s sake? I can chalk this out if we’re in agreement.Hi @evilsoft. Yes, that
joinM
will be very helpful to me. Thanks a lot!Here are some random - probably not mathematically sound - brainstorm ideas:
unbox
unNest
unlade
uncrate
merge
meld
smoosh
squash
fuse
melt
On a different note, I wanted to say earlier that I’m really enjoying this library. I tried a few other functional libraries after reading this book and they felt rather abstruse. Things are really clicking for me with
crocks
. Thanks a lot!