Real World

intermediate5 of 5

Learn about real world in fp-ts pipe

Code Editor

05-real-world.exercise.ts

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

Test Results

Requirements

describe('extractUserAge', () => {
  it('extracts age from complete response', () => {
    const response: ApiResponse = {
      data: {
        user: {
          profile: {
            name: 'Alice',
            age: 25
          }
        }
      }
    }
    const result = extractUserAge(response)
    expect(result).toEqual({ _tag: 'Some', value: 25 })
  })

  it('returns None when data is missing', () => {
    const response: ApiResponse = {}
    const result = extractUserAge(response)
    expect(result).toEqual({ _tag: 'None' })
  })

  it('returns None when user is missing', () => {
    const response: ApiResponse = {
      data: {}
    }
    const result = extractUserAge(response)
    expect(result).toEqual({ _tag: 'None' })
  })

  it('returns None when profile is missing', () => {
    const response: ApiResponse = {
      data: {
        user: {}
      }
    }
    const result = extractUserAge(response)
    expect(result).toEqual({ _tag: 'None' })
  })
})
🧪

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