Struct
Learn about struct in fp-ts semigroup
Code Editor
02-struct.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Semigroup struct', () => {
it('combines points by adding coordinates', () => {
const p1 = { x: 1, y: 2 }
const p2 = { x: 3, y: 4 }
const result = combinePoints(p1, p2)
expect(result).toEqual({ x: 4, y: 6 })
})
it('combines multiple stats', () => {
const stats = [
{ count: 5, total: 100 },
{ count: 3, total: 50 },
{ count: 2, total: 30 },
]
const result = combineStats(stats)
expect(result).toEqual({ count: 10, total: 180 })
})
it('handles single stat', () => {
const result = combineStats([{ count: 7, total: 42 }])
expect(result).toEqual({ count: 7, total: 42 })
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
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