Flatmap

advanced8 of 10

Learn about flatmap in fp-ts array

Code Editor

08-flatmap.exercise.ts

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

Test Results

Requirements

describe('Array flatMap operations', () => {
  it('gets all hobbies from all users', () => {
    const users: User[] = [
      { name: 'Alice', hobbies: ['reading', 'gaming'] },
      { name: 'Bob', hobbies: ['cooking'] },
      { name: 'Charlie', hobbies: ['running', 'cycling', 'swimming'] },
    ]
    const result = getAllHobbies(users)
    expect(result).toEqual(['reading', 'gaming', 'cooking', 'running', 'cycling', 'swimming'])
  })

  it('explodes numbers into pairs', () => {
    const result = explodeNumbers([1, 2, 3])
    expect(result).toEqual([1, 1, 2, 2, 3, 3])
  })

  it('handles empty array', () => {
    const result = getAllHobbies([])
    expect(result).toEqual([])
  })
})
🧪

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