Chain

intermediate4 of 8

Learn about chain in fp-ts reader

Code Editor

04-chain.exercise.ts

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

Test Results

Requirements

describe('Reader chain', () => {
  const config: Config = {
    database: {
      host: 'localhost',
      port: 5432,
    },
    appName: 'myapp',
  }

  it('gets database config', () => {
    const result = getDatabase()(config)
    expect(result).toEqual({ host: 'localhost', port: 5432 })
  })

  it('builds connection string', () => {
    const result = getConnectionString()(config)
    expect(result).toBe('localhost:5432')
  })

  it('builds full connection string with app name', () => {
    const result = getFullConnectionString()(config)
    expect(result).toBe('myapp@localhost:5432')
  })
})
🧪

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