Lookup
Learn about lookup in fp-ts record
Code Editor
04-lookup.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Record lookup operations', () => {
it('looks up existing key', () => {
const record = { a: 10, b: 20, c: 30 }
const result = getValue(record, 'b')
expect(O.isSome(result)).toBe(true)
expect(result).toEqual(O.some(20))
})
it('returns None for missing key', () => {
const record = { a: 10 }
const result = getValue(record, 'z')
expect(O.isNone(result)).toBe(true)
})
it('gets value with default', () => {
const record = { a: 10, b: 20 }
expect(getValueWithDefault(record, 'a', 0)).toBe(10)
expect(getValueWithDefault(record, 'z', 999)).toBe(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