Struct
Learn about struct in fp-ts monoid
Code Editor
02-struct.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Monoid struct', () => {
it('combines multiple carts', () => {
const carts = [
{ items: 3, totalPrice: 50, couponCode: '' },
{ items: 2, totalPrice: 30, couponCode: 'SAVE10' },
{ items: 1, totalPrice: 20, couponCode: '' },
]
const result = combineCart(carts)
expect(result).toEqual({
items: 6,
totalPrice: 100,
couponCode: 'SAVE10',
})
})
it('handles empty array', () => {
const result = combineCart([])
expect(result).toEqual({
items: 0,
totalPrice: 0,
couponCode: '',
})
})
it('handles single cart', () => {
const result = combineCart([{ items: 5, totalPrice: 75, couponCode: 'FIRST' }])
expect(result).toEqual({ items: 5, totalPrice: 75, couponCode: 'FIRST' })
})
})🧪
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