From Options

intermediate4 of 6

Learn about from options in fp-ts these

Code Editor

04-from-options.exercise.ts

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

Test Results

Requirements

describe('These from Options', () => {
  it('creates left from Some/None', () => {
    const result = fromOptions(O.some('error'), O.none)
    expect(result).toEqual(O.some(Th.left('error')))
  })

  it('creates right from None/Some', () => {
    const result = fromOptions(O.none, O.some(42))
    expect(result).toEqual(O.some(Th.right(42)))
  })

  it('creates both from Some/Some', () => {
    const result = fromOptions(O.some('warning'), O.some(42))
    expect(result).toEqual(O.some(Th.both('warning', 42)))
  })

  it('returns None from None/None', () => {
    const result = fromOptions(O.none, O.none)
    expect(result).toEqual(O.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