Map

beginner3 of 6

Learn about map in fp-ts these

Code Editor

03-map.exercise.ts

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

Test Results

Requirements

describe('These map', () => {
  it('maps right value', () => {
    const result = doubleValue(Th.right(21))
    expect(result).toEqual(Th.right(42))
  })

  it('maps both value', () => {
    const result = doubleValue(Th.both('warning', 21))
    expect(result).toEqual(Th.both('warning', 42))
  })

  it('leaves left unchanged', () => {
    const result = doubleValue(Th.left('error'))
    expect(result).toEqual(Th.left('error'))
  })

  it('transforms both sides', () => {
    const result = transformBoth(Th.both('warning', 42))
    const expected = Th.both('WARNING: warning', 'Value: 42')
    expect(result).toEqual(expected)
  })
})
🧪

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