From Nullable
Learn about from nullable in fp-ts option
Code Editor
05-from-nullable.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('getUserAddress', () => {
const user1: User = { id: 1, name: 'Alice', age: 25 }
const user2: User = { id: 2, name: 'Bob', age: 30, address: '123 Main St' }
const user3: User = { id: 3, name: 'Charlie', age: 35, address: null }
it('returns O.none if user has no address', () => {
const result = getUserAddress(user1)
expect(result).toEqual({ _tag: 'None' })
})
it('returns some with the address if user has an address', () => {
const result = getUserAddress(user2)
expect(result).toEqual({ _tag: 'Some', value: '123 Main St' })
})
it('returns O.none if user has a null address', () => {
const result = getUserAddress(user3)
expect(result).toEqual({ _tag: 'None' })
})
})
🧪
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