The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

376034 (11) [Avatar] Offline
#1
This is a code sample from page 183.
I would like to ask: Isn't this not good functional programming practice in that the body of the getPhotoUrl function grabs photoArray from the outside instead of passing it into this function as an argument?

getPhotoUrl: Int -> String
getPhotoUrl index = 
  case Array.get index photoArray of
    Just photo -> photo.url
    Nothing -> ""
18541 (2) [Avatar] Offline
#2
376034 wrote:This is a code sample from page 183.
I would like to ask: Isn't this not good functional programming practice in that the body of the getPhotoUrl function grabs photoArray from the outside instead of passing it into this function as an argument?

getPhotoUrl: Int -> String
getPhotoUrl index = 
  case Array.get index photoArray of
    Just photo -> photo.url
    Nothing -> ""


Good point. I see a similar issue with the usage of urlPrefix. Both the view and viewThumbnail functions reference urlPrefix which isn't passed in. This would seem to make these two functions 'impure'. I'm new to FP, so am I overlooking some reason why this is ok?