With Either

intermediate4 of 5

Learn about with either in fp-ts flow

Code Editor

04-with-either.exercise.ts

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

Test Results

Requirements

describe('validateEmailAddress', () => {
  it('accepts valid email', () => {
    const result = validateEmailAddress('test@example.com')
    expect(result).toEqual({ _tag: 'Right', right: 'test@example.com' })
  })

  it('rejects empty string', () => {
    const result = validateEmailAddress('')
    expect(result).toEqual({ _tag: 'Left', left: 'Empty string' })
  })

  it('rejects too short', () => {
    const result = validateEmailAddress('a@b')
    expect(result).toEqual({ _tag: 'Left', left: 'Too short' })
  })

  it('rejects invalid format', () => {
    const result = validateEmailAddress('notanemail')
    expect(result).toEqual({ _tag: 'Left', left: 'Invalid format' })
  })
})
🧪

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