Ask

beginner3 of 8

Learn about ask in fp-ts reader

Code Editor

03-ask.exercise.ts

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

Test Results

Requirements

describe('Reader ask', () => {
  const context: AppContext = {
    currentUser: {
      id: 1,
      name: 'Alice',
      email: 'alice@example.com',
    },
    isAdmin: true,
  }

  it('gets current user name', () => {
    expect(getCurrentUserName()(context)).toBe('Alice')
  })

  it('gets current user email', () => {
    expect(getCurrentUserEmail()(context)).toBe('alice@example.com')
  })

  it('checks if user is admin', () => {
    expect(isCurrentUserAdmin()(context)).toBe(true)
  })

  it('works with non-admin user', () => {
    const userContext = { ...context, isAdmin: false }
    expect(isCurrentUserAdmin()(userContext)).toBe(false)
  })
})
🧪

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