Map

beginner2 of 8

Learn about map in fp-ts reader

Code Editor

02-map.exercise.ts

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

Test Results

Requirements

describe('Reader map', () => {
  const config: Config = {
    apiUrl: 'https://api.example.com',
    version: 2,
  }

  it('builds full URL with endpoint', () => {
    const result = getFullUrl('users')(config)
    expect(result).toBe('https://api.example.com/v2/users')
  })

  it('works with different endpoints', () => {
    expect(getFullUrl('posts')(config)).toBe('https://api.example.com/v2/posts')
    expect(getFullUrl('comments')(config)).toBe('https://api.example.com/v2/comments')
  })

  it('uses version from config', () => {
    const v1Config = { ...config, version: 1 }
    expect(getFullUrl('users')(v1Config)).toBe('https://api.example.com/v1/users')
  })
})
🧪

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