Accumulate

beginner2 of 7

Learn about accumulate in fp-ts validation

Code Editor

02-accumulate.exercise.ts

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

Test Results

Requirements

describe('Accumulating validation errors', () => {
  it('validates correct name', () => {
    const result = validateName('Alice')
    expect(result._tag).toBe('Right')
  })

  it('accumulates name errors', () => {
    const result = validateName('A')
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left.length).toBeGreaterThan(0)
    }
  })

  it('validates correct password', () => {
    const result = validatePassword('SecurePass123')
    expect(result._tag).toBe('Right')
  })

  it('accumulates password errors', () => {
    const result = validatePassword('weak')
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left.length).toBeGreaterThan(1) // Multiple errors
    }
  })
})
🧪

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