Practical
Learn about practical in fp-ts readertaskeither
Code Editor
08-practical.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('ReaderTaskEither practical', () => {
const config: AppConfig = {
apiUrl: 'https://api.example.com',
apiKey: 'secret',
cache: { user1: { id: 1, name: 'Alice' } },
}
it('fetches from cache when available', async () => {
const result = await fetchFromCache('user1')(config)()
expect(E.isRight(result)).toBe(true)
if (E.isRight(result)) {
expect(result.right).toEqual({ id: 1, name: 'Alice' })
}
})
it('fails when cache miss', async () => {
const result = await fetchFromCache('user999')(config)()
expect(E.isLeft(result)).toBe(true)
})
it('fetches from API with config', async () => {
const result = await fetchFromApi('/users/1')(config)()
expect(E.isRight(result)).toBe(true)
if (E.isRight(result)) {
expect(result.right).toEqual({ data: 'https://api.example.com/users/1' })
}
})
it('uses fallback when cache misses', async () => {
const result = await fetchWithFallback('user999', '/users/999')(config)()
expect(E.isRight(result)).toBe(true)
if (E.isRight(result)) {
expect(result.right).toEqual({ data: 'https://api.example.com/users/999' })
}
})
})🧪
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