Guest User

Untitled

a guest
Dec 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /**
  2. * Returns a set transformed by applying `f` to each element of `s`.
  3. */
  4. def map(s: Set, f: Int => Int): Set = {
  5. val bound = 10
  6. def loop(s: Set, f: Int => Int): Set = {
  7. def iter(a: Int, acc: Set): Set = {
  8. if (a > bound) acc
  9. else if(contains(s, a)) {
  10. if(acc == null) iter(a + 1, singletonSet(f(a)))
  11. else iter(a + 1, union(acc, singletonSet(f(a))))
  12. }
  13. else iter(a + 1, acc)
  14. }
  15. iter(-bound, null)
  16. }
  17. loop(s, f)
  18. }
Add Comment
Please, Sign In to add comment