Basic

beginner1 of 7

Learn about basic in fp-ts validation

Code Editor

01-basic.exercise.ts

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

Test Results

Requirements

describe('Validation basics', () => {
  it('validates age successfully', () => {
    const result = validateAge(25)
    expect(result._tag).toBe('Right')
    if (result._tag === 'Right') {
      expect(result.right).toBe(25)
    }
  })

  it('rejects invalid age', () => {
    expect(validateAge(-5)._tag).toBe('Left')
    expect(validateAge(150)._tag).toBe('Left')
  })

  it('validates email successfully', () => {
    const result = validateEmail('user@example.com')
    expect(result._tag).toBe('Right')
  })

  it('rejects invalid email', () => {
    const result = validateEmail('invalid-email')
    expect(result._tag).toBe('Left')
  })
})
🧪

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