Pipeline

advanced10 of 10

Learn about pipeline in fp-ts taskeither

Code Editor

10-pipeline.exercise.ts

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

Test Results

Requirements

describe('TaskEither complex pipeline', () => {
  it('processes valid users', async () => {
    const users: User[] = [
      { id: 1, email: 'alice@example.com', age: 25 },
      { id: 2, email: 'bob@example.com', age: 35 },
      { id: 3, email: 'charlie@example.com', age: 55 },
    ]

    const result = await processUsers(users)()
    expect(result._tag).toBe('Right')
    if (result._tag === 'Right') {
      expect(result.right).toEqual([
        { id: 1, email: 'alice@example.com', ageGroup: 'young' },
        { id: 2, email: 'bob@example.com', ageGroup: 'middle' },
        { id: 3, email: 'charlie@example.com', ageGroup: 'senior' },
      ])
    }
  })

  it('fails on invalid user', async () => {
    const users: User[] = [
      { id: 1, email: 'alice@example.com', age: 25 },
      { id: 2, email: 'invalid-email', age: 16 },
    ]

    const result = await processUsers(users)()
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left.length).toBeGreaterThan(0)
    }
  })
})
🧪

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