我还在学习这种外星人的功能范式......
我将如何在 Clojure 中以一种功能性的方式编写以下代码?假设这个缺失的部分是在别处定义的,并且行为如评论中所述。这是我熟悉的Python。
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()
我真正需要知道的是如何建立一个新的回调字典,就像在reopenAll函数中一样,但是我在这里包含了更多的上下文,因为我可能会犯某种功能范式暴行,你会最可能想要修复整个程序。:)