๐Functional Pipeline LabLAB
Functional Pipeline Lab
In this lab, you will implement three higher-order functions and chain them together into a pipeline.
Your Task
Implement these three functions:
1. filter(nums []int, keep func(int) bool) []int
- Returns a new slice containing only elements where
keep(element)returnstrue
2. mapInts(nums []int, fn func(int) int) []int
- Returns a new slice with
fnapplied to each element
3. reduce(nums []int, init int, fn func(int, int) int) int
- Folds the slice into a single value, starting with
init
Then in main, apply the pipeline to []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}:
- Filter even numbers โ print the filtered slice
- Double each number with mapInts โ print the doubled slice
- Sum with reduce โ print the final sum
Expected Output
โ Enter (Mac) ยท Ctrl+Enter (Win/Linux)
โ Enter (Mac) ยท Ctrl+Enter (Win/Linux)