Map

intermediate4 of 10

Learn about map in fp-ts taskeither

Code Editor

04-map.exercise.ts

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

Test Results

Requirements

describe('TaskEither map operations', () => {
  it('maps success value', async () => {
    const task = TE.right(21)
    const result = await doubleSuccess(task)()
    expect(result._tag).toBe('Right')
    if (result._tag === 'Right') {
      expect(result.right).toBe(42)
    }
  })

  it('does not affect errors on map', async () => {
    const task = TE.left('error')
    const result = await doubleSuccess(task)()
    expect(result._tag).toBe('Left')
  })

  it('maps error value', async () => {
    const task = TE.left('failure')
    const result = await prefixError(task)()
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left).toBe('ERROR: failure')
    }
  })

  it('does not affect success on mapLeft', async () => {
    const task = TE.right(42)
    const result = await prefixError(task)()
    expect(result._tag).toBe('Right')
  })
})
🧪

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