From Either

advanced10 of 10

Learn about from either in fp-ts option

Code Editor

10-from-either.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('getUserOptionById', () => {
  it('returns O.none if user ID is less than 1', () => {
    const result = getUserOptionById(0)
    expect(result).toEqual(O.none)
  })

  it('returns a some object with the user if user ID is valid', () => {
    const result = getUserOptionById(2)
    expect(result).toEqual(O.some({ id: 2, name: 'User 2', age: 20 }))
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

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