Practical

advanced7 of 7

Learn about practical in fp-ts io

Code Editor

07-practical.exercise.ts

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

Test Results

Requirements

describe('IOEither practical', () => {
  it('loads valid config', () => {
    const result = loadConfig('dev')()
    expect(E.isRight(result)).toBe(true)
    if (E.isRight(result)) {
      expect(result.right).toEqual({ timeout: 5000, retries: 3 })
    }
  })

  it('fails on missing config', () => {
    const result = loadConfig('staging')()
    expect(E.isLeft(result)).toBe(true)
  })

  it('validates config successfully', () => {
    const config: Config = { timeout: 5000, retries: 3 }
    const result = validateConfig(config)()
    expect(E.isRight(result)).toBe(true)
  })

  it('fails validation for invalid config', () => {
    const config: Config = { timeout: -1, retries: 3 }
    const result = validateConfig(config)()
    expect(E.isLeft(result)).toBe(true)
  })

  it('loads and validates config', () => {
    const result = loadAndValidateConfig('prod')()
    expect(E.isRight(result)).toBe(true)
  })
})
🧪

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