Chain
Learn about chain in fp-ts either
Code Editor
04-chain.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('findAndValidateUser', () => {
const users = [
{ id: 1, name: 'Alice', age: 25 },
{ id: 2, name: 'Bob', age: 16 },
{ id: 3, name: 'Charlie', age: 30 },
]
it('returns right with user if valid and adult', () => {
const result = findAndValidateUser(1, users)
expect(result).toEqual({ _tag: 'Right', right: { id: 1, name: 'Alice', age: 25 } })
})
it('returns left if ID is invalid', () => {
const result = findAndValidateUser(0, users)
expect(result).toEqual({ _tag: 'Left', left: 'Invalid ID' })
})
it('returns left if user not found', () => {
const result = findAndValidateUser(99, users)
expect(result).toEqual({ _tag: 'Left', left: 'User not found' })
})
it('returns left if user too young', () => {
const result = findAndValidateUser(2, users)
expect(result).toEqual({ _tag: 'Left', left: 'User too young' })
})
})🧪
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