question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing "join" method on ADTs

See original GitHub issue

Based 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
karthikiyengarcommented, Jul 22, 2019

I have strong memories of missing this function, and this looks useful for sure. Since we’re prefixing m to most array-colliding functions like mconcat, mreduce et al, we could even consider mjoin for consistency’s sake? I can chalk this out if we’re in agreement.

2reactions
mrhubbscommented, Apr 9, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found