Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'json'
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ First in Python:
u'https://api.spotify.com/v1/artists/1vCWHaC5f2uS3yhpwWbIA6/albums?offset=0&limit=5&album_type=single&market=ES'
```

Second, in Ruby:

```ruby
require 'json'
albums = JSON.parse(File.read('albums.json'))
puts albums['href']
u'https://api.spotify.com/v1/artists/1vCWHaC5f2uS3yhpwWbIA6/albums?offset=0&limit=5&album_type=single&market=ES'
```

In Haskell:

```
Expand All @@ -89,6 +98,14 @@ Python:
u'single'
```

Ruby:

```
puts albums['items'][0]['album_type']

Example two is: single
```

Haskell:

```haskell
Expand All @@ -106,13 +123,23 @@ Python:
# list comprehension version
>>> [item['name'] for item in albums['items']]
[u'Taste The Feeling (Avicii Vs. Conrad Sewell)', u'Pure Grinding (iSHi Remix)', u'Broken Arrows (Remixes)', u'For A Better Day (Remixes
)', u'For A Better Day (KSHMR Remix)']
)', u'For A Better Day (KSHMR Remix)']
```

```python
# for loop version
lst = []
for name in albums['items']:
lst.append(name)
```
Ruby:
```ruby
list = []
for name in albums['items']
list.push(name)
end
puts list
```

Haskell:
```
Expand Down Expand Up @@ -143,12 +170,22 @@ for item in albums['items']:
lst.append(image['height'])
```

Ruby:
```ruby
list2 = []
for item in albums['items']
for image in item['images']
list2.push(image['height'])
end
end
```

```haskell
λ> toListOf (\obj -> key "items" (values (key "images" (values (key "height" (_Number obj)))))) albums
[640.0,300.0,64.0,640.0,300.0,64.0,640.0,300.0,64.0,640.0,300.0,64.0,640.0,300.0,64.0]
```

Now let's do something like we'd actually be asked to do at our jobs.
Now let's do something like we'd actually be asked to do at our jobs.

Boss: What albums are available in the HK and LU markets?!?

Expand All @@ -170,7 +207,7 @@ Of course for me, this is well past the point where I usually start naming my le
λ> let availableMarkets album = key "available_markets" (values (_String album))
λ> let isHkOrLU i = i `elem` ["HK","LU"]
λ> let albumName album = key "name" (_String album)
λ> toListOf (\album -> items (filtered (anyOf availableMarkets isHkOrLU) (albumName album))) albums
λ> toListOf (\album -> items (filtered (anyOf availableMarkets isHkOrLU) (albumName album))) albums
["Taste The Feeling (Avicii Vs. Conrad Sewell)","Pure Grinding (iSHi Remix)","Broken Arrows (Remixes)","For A Better Day (Remixes)","For A Better Day (KSHMR Remix)"]
```

Expand Down
Loading