In this tutorial you’ll learn, step by step, how to get started with functional programming and how to write declarative, rather than imperative, code.
Hi there! I think there is a typo here in the code in Map section, where you’re providing example of re-implementation of sortedNamesImp(_:) as sortedNamesFP(_:).
parkRides is an array of Ride objects, which contains a “name” property. This array is declared earlier in the article as a let (i.e. immutable) object.
@syedfa Thanks for reply!
I’m new to Swift and programming, so could be i didn’t figure out it correctly. But still I have some doubts.
this function is assigned to constant in the article:
let sortedNames2 = sortedNamesFP(parkRides)
testSortedNames(sortedNames2)
in the case there is no typo in original code, then function works regardless of what i give as parameter. In below example if i pass empty array, the value of constant is the same in my playground.
let sortedNames2 = sortedNamesFP()
testSortedNames(sortedNames2)
You are correct. There is a bug in that function in that it’s using the externally defined variable instead of the passed through array. The correct version should be