Practical
Learn about practical in fp-ts monoid
Code Editor
04-practical.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Monoid practical examples', () => {
it('aggregates page metrics', () => {
const metrics = [
{ views: 100, likes: 10, shares: 5, comments: 3 },
{ views: 200, likes: 20, shares: 8, comments: 7 },
{ views: 150, likes: 15, shares: 3, comments: 5 },
]
const result = aggregateMetrics(metrics)
expect(result).toEqual({
views: 450,
likes: 45,
shares: 16,
comments: 15,
})
})
it('handles empty metrics', () => {
const result = aggregateMetrics([])
expect(result).toEqual({ views: 0, likes: 0, shares: 0, comments: 0 })
})
it('combines feature flags with OR logic', () => {
const flags = [
{ darkMode: false, notifications: true, analytics: false },
{ darkMode: true, notifications: false, analytics: false },
{ darkMode: false, notifications: false, analytics: true },
]
const result = combineFeatureFlags(flags)
expect(result).toEqual({
darkMode: true, // At least one true
notifications: true,
analytics: true,
})
})
it('handles all false flags', () => {
const flags = [
{ darkMode: false, notifications: false, analytics: false },
{ darkMode: false, notifications: false, analytics: false },
]
const result = combineFeatureFlags(flags)
expect(result).toEqual({ darkMode: false, notifications: false, analytics: false })
})
})🧪
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