Comparison
Learn about comparison in fp-ts validation
Code Editor
05-comparison.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Either vs Validation comparison', () => {
it('Either fails fast', () => {
const result = validateUserEither('', -5)
expect(result._tag).toBe('Left')
if (result._tag === 'Left') {
// Only gets first error
expect(typeof result.left).toBe('string')
}
})
it('Validation accumulates errors', () => {
const result = validateUserValidation('', -5)
expect(result._tag).toBe('Left')
if (result._tag === 'Left') {
// Gets both errors
expect(result.left.length).toBe(2)
}
})
it('Both succeed with valid input', () => {
const result1 = validateUserEither('Alice', 25)
const result2 = validateUserValidation('Alice', 25)
expect(result1._tag).toBe('Right')
expect(result2._tag).toBe('Right')
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
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