Map

beginner2 of 8

Learn about map in fp-ts either

Code Editor

02-map.exercise.ts

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

Test Results

Requirements

describe('getUserEmail', () => {
  const user: User = { id: 1, name: 'Alice', email: 'alice@example.com' }
  const userRight: E.Either<UserError, User> = E.right(user)
  const userLeft: E.Either<UserError, User> = E.left('User not found')

  it('maps right value to email', () => {
    const result = getUserEmail(userRight)
    expect(result).toEqual({ _tag: 'Right', right: 'alice@example.com' })
  })

  it('preserves left value', () => {
    const result = getUserEmail(userLeft)
    expect(result).toEqual({ _tag: 'Left', left: 'User not found' })
  })
})
🧪

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