Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns a set transformed by applying `f` to each element of `s`.
- */
- def map(s: Set, f: Int => Int): Set = {
- val bound = 10
- def loop(s: Set, f: Int => Int): Set = {
- def iter(a: Int, acc: Set): Set = {
- if (a > bound) acc
- else if(contains(s, a)) {
- if(acc == null) iter(a + 1, singletonSet(f(a)))
- else iter(a + 1, union(acc, singletonSet(f(a))))
- }
- else iter(a + 1, acc)
- }
- iter(-bound, null)
- }
- loop(s, f)
- }
Add Comment
Please, Sign In to add comment