forked from DrBoolean/spotify-fp-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 774 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict'
const Task = require('data.task')
const Spotify = require('./spotify')
const {List} = require('immutable-ext')
const {Pair, Sum} = require('./monoid')
const Intersection = require('./monoids/intersection')
const argv = new Task((rej, res) => res(process.argv))
const names = argv.map(args => args.slice(2))
const related = name =>
Spotify.findArtist(name)
.map(artist => artist.id)
.chain(Spotify.relatedArtists)
.map(artists => artists.map(artist => artist.name))
const artistIntersection = rels =>
rels
.foldMap(x => Pair(Intersection(x), Sum(x.length)))
.bimap(x => x.xs, y => y.x)
.toList()
const main = names =>
List(names)
.traverse(Task.of, related)
.map(artistIntersection)
names.chain(main).fork(console.error, console.log)