Ioeither Basic

beginner3 of 7

Learn about ioeither basic in fp-ts io

Code Editor

03-ioeither-basic.exercise.ts

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

Test Results

Requirements

describe('IOEither basic', () => {
  it('divides safely', () => {
    const result = safeDivide(10, 2)()
    expect(E.isRight(result)).toBe(true)
    if (E.isRight(result)) {
      expect(result.right).toBe(5)
    }
  })

  it('fails on division by zero', () => {
    const result = safeDivide(10, 0)()
    expect(E.isLeft(result)).toBe(true)
    if (E.isLeft(result)) {
      expect(result.left).toBe('Division by zero')
    }
  })

  it('always succeeds', () => {
    const result = alwaysSucceed('test')()
    expect(E.isRight(result)).toBe(true)
    if (E.isRight(result)) {
      expect(result.right).toBe('test')
    }
  })
})
🧪

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