With Option

beginner2 of 5

Learn about with option in fp-ts flow

Code Editor

02-with-option.exercise.ts

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

Test Results

Requirements

describe('getUserEmailById', () => {
  it('returns Some with email when user found', () => {
    const result = getUserEmailById(1)
    expect(result).toEqual({ _tag: 'Some', value: 'alice@example.com' })
  })

  it('returns None when user not found', () => {
    const result = getUserEmailById(99)
    expect(result).toEqual({ _tag: 'None' })
  })

  it('is reusable', () => {
    expect(getUserEmailById(2)).toEqual({ _tag: 'Some', value: 'bob@example.com' })
    expect(getUserEmailById(1)).toEqual({ _tag: 'Some', value: 'alice@example.com' })
  })
})
🧪

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