|
|
|
|
|
by bko
1992 days ago
|
|
> a.zip(b).map(func1).filter(func2).forall(func3) Lets make this a somewhat concrete example. --- heights = [1,2,3] widths = [4,5,6] # printing area greater than 10 # functional heights.zip(widths).map(to_area).filter(lambda area: area > 10).forall(lambda a: print("Area " + a) #Verbose way hw_zipped = zip(a,b) areas = hw_zipped.map(to_inches) big_areas = areas.filter(a: a > 10) for a in big_areas:
print("Area " + a) --- Which do you prefer? I would argue the right level of abstraction is the functional way in this example, and its often the case in my experience, especially in python where you don't often use a namespace to store these intermediary variables and you have can't rely on typing |
|