Fold

intermediate4 of 10

Learn about fold in fp-ts option

Code Editor

04-fold.exercise.ts

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

Test Results

Requirements

describe('getUserEmail', () => {
  const user1: O.Option<User> = O.some({
    id: 1,
    name: 'Alice',
    email: 'alice@example.com',
  })
  const user2: O.Option<User> = O.none

  it('returns user email if available', () => {
    const result = getUserEmail(user1)
    expect(result).toEqual('alice@example.com')
  })

  it('returns default message if user email is not available', () => {
    const result = getUserEmail(user2)
    expect(result).toEqual('User email not available')
  })
})
🧪

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