Some And None

beginner1 of 10

Learn about some and none in fp-ts option

Code Editor

01-some-and-none.exercise.ts

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

Test Results

Requirements

describe('getUserById', () => {
  const users = [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' },
    { id: 3, name: 'Charlie' },
  ]

  it('returns an option with user if it exists', () => {
    const user = getUserById(users, 2)
    expect(user).toEqual({ _tag: 'Some', value: { id: 2, name: 'Bob' } })
  })

  it('returns O.none if user does not exist', () => {
    const user = getUserById(users, 4)
    expect(user).toEqual({ _tag: 'None' })
  })
})
🧪

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