Chain
Learn about chain in fp-ts readertaskeither
Code Editor
04-chain.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('ReaderTaskEither chain', () => {
const env: Env = {
users: {
1: { id: 1, name: 'Alice', companyId: 10 },
2: { id: 2, name: 'Bob', companyId: 20 },
},
companies: {
10: { id: 10, name: 'Acme Corp' },
20: { id: 20, name: 'Tech Inc' },
},
}
it('fetches user with company', async () => {
const result = await fetchUserWithCompany(1)(env)()
expect(E.isRight(result)).toBe(true)
if (E.isRight(result)) {
expect(result.right).toEqual({ user: 'Alice', company: 'Acme Corp' })
}
})
it('fails when user not found', async () => {
const result = await fetchUserWithCompany(999)(env)()
expect(E.isLeft(result)).toBe(true)
if (E.isLeft(result)) {
expect(result.left).toBe('User 999 not found')
}
})
})🧪
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