How should I build a list and return it in clojure?

Viewed 153

I'm still learning this alien functional paradigm...

How would I write the following code in Clojure, and in a functional way? assume this missing parts are defined elsewhere and behave as described in the comments. Here it is in Python, which I am familiar with.

usernames = []
# just the usernames of all the connections I want to open.
cancelfunctions = {}
# this global contains anonymous functions to cancel connections, keyed by username

def cancelAll():
    for cancel in cancelfunctions.values():
        cancel()

def reopenAll():
    cancelfunctions = {}
    for name in usernames:
        # should return a function to close the connection and put it in the dict.
        cancelfunctions[name] = openConnection()

All I really need to know is how to build up a new dict of callbacks, like in the reopenAll function, but I'm including some more context here because chances are I'm committing some kind of functional paradigm atrocity, and you will most likely want to fix the whole program. :)

2 Answers
Related