Recovery

intermediate6 of 10

Learn about recovery in fp-ts taskeither

Code Editor

06-recovery.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('TaskEither recovery', () => {
  it('retries task on failure', async () => {
    let attempts = 0
    const task = TE.tryCatch(
      async () => {
        attempts++
        if (attempts === 1) throw new Error('First attempt')
        return 42
      },
      () => 'failed'
    )

    const result = await retryOnce(task)()
    expect(result._tag).toBe('Right')
    expect(attempts).toBe(2)
  })

  it('succeeds on first attempt', async () => {
    let attempts = 0
    const task = TE.tryCatch(
      async () => {
        attempts++
        return 100
      },
      () => 'failed'
    )

    const result = await retryOnce(task)()
    expect(result._tag).toBe('Right')
    expect(attempts).toBe(1)
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

Pro Tips

💡 Stuck? Here's what to try:

  • • Read the comments in the code carefully
  • • Run tests frequently to get feedback
  • • Check the fp-ts documentation
  • • Use the solution if you need help

🚀 Learning Approach:

  • • Focus on understanding, not just solving
  • • Experiment with different approaches
  • • Think about real-world applications
  • • Build on previous exercises