-
Notifications
You must be signed in to change notification settings - Fork 148
Martin Fowler's closure examples in boo
rollynoel edited this page Jun 13, 2013
·
2 revisions
Added by Bill Wood
Below are boo versions of the examples in Martin Fowler's blog on closures:
class emp:
public isManager = false
public name = ""
public salary = 100
def ToString():
return name
def managers(emps as List):
return emps.Collect({ e as emp | return e.isManager})
def highPaid(emps as List):
threshold = 150
return emps.Collect({ e as emp | return e.salary > threshold})
def paidMore(amount as int):
return { e as emp | return e.salary > amount}
emps = [emp(name:"Bill", isManager: true), emp(name: "Sally"), emp(name: "Molly", isManager: true)]
print managers(emps)
highPaid2 = paidMore(150)
john = emp(name: "John")
john.salary = 200
print highPaid2(john)