Get Or Else
Learn about get or else in fp-ts either
Code Editor
07-get-or-else.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('getUserName', () => {
const userRight: E.Either<UserError, User> = E.right({ id: 1, name: 'Alice' })
const userLeft: E.Either<UserError, User> = E.left('User not found')
it('returns user name for right value', () => {
const result = getUserName(userRight)
expect(result).toEqual('Alice')
})
it('returns default value for left', () => {
const result = getUserName(userLeft)
expect(result).toEqual('Anonymous')
})
})🧪
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