Local

intermediate6 of 8

Learn about local in fp-ts reader

Code Editor

06-local.exercise.ts

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

Test Results

Requirements

describe('Reader local', () => {
  const config: Config = {
    baseUrl: 'https://api.example.com',
    apiKey: 'secret123',
    timeout: 5000,
  }

  it('gets base URL from config', () => {
    expect(getUrl()(config)).toBe('https://api.example.com')
  })

  it('overrides URL locally without affecting original config', () => {
    const result = getUrlWithOverride('https://test.com')(config)
    expect(result).toBe('https://test.com')
    // Original config unchanged
    expect(getUrl()(config)).toBe('https://api.example.com')
  })

  it('overrides timeout locally', () => {
    const result = getUrlWithTimeout(1000)(config)
    expect(result).toEqual({
      url: 'https://api.example.com',
      timeout: 1000,
    })
  })

  it('multiple local overrides work independently', () => {
    expect(getUrlWithOverride('https://dev.com')(config)).toBe('https://dev.com')
    expect(getUrlWithOverride('https://staging.com')(config)).toBe('https://staging.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