mapversion is one expression. It does not require any order of evaluation. There is much freedom here for how the map function iterates and how the returned array may be assembled. It specifies what, not how. Thus, it wears the shiny declarative sash.
composeexpression simply states a fact: Authentication is the composition of
logIn. Again, this leaves wiggle room for support code changes and results in our application code being a high level specification.
toUsermust be called before
logIn), but there are many scenarios where the order is not important, and this is easily specified with declarative coding (more on this later).
curry, and more. I've used requirejs, which may seem like overkill, but we'll be using it throughout the book and consistency is key.
tracefunction for easy debugging.
Impureso we know these are dangerous functions. In a future example, we will make these two functions pure.
urlpointfree using monoids(we'll learn about these later) or combinators. We've chosen to stick with a readable version and assemble this string in the normal pointful fashion.
urlfunction, then passes the string to our
getJSONfunction, which has been partially applied with
trace. Loading the app will show the response from the api call in the console.
mediaUrlsare buried in
prop. Here's a homegrown version so you can see what's happening:
syntax to access a property on whatever object. Let's use this to get at our
items, we must
mapover them to extract each media url. This results in a nice array of
mediaUrls. Let's hook this up to our app and print them on the screen.
mediaUrlsand set the
<main>html with them. We've replaced the
rendernow that we have something to render besides raw json. This will crudely display our
mediaUrlswithin the body.
images. In a bigger application, we'd use a template/dom library like Handlebars or React. For this application though, we only need an img tag so let's stick with jQuery.
htmlmethod will accept an array of tags. We only have to transform our mediaUrls into images and send them along to
imagesthanks to equational reasoning and purity.
maps we can apply the composition law.