-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.mjs
More file actions
32 lines (27 loc) · 983 Bytes
/
main.mjs
File metadata and controls
32 lines (27 loc) · 983 Bytes
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
30
31
32
import W from 'mojiscript/combinators/W'
import pipe from 'mojiscript/core/pipe'
import join from 'mojiscript/list/join'
import map from 'mojiscript/list/map'
import ifElse from 'mojiscript/logic/ifElse'
import prepend from 'mojiscript/string/prepend'
import $ from 'mojiscript/string/template'
import isEmpty from 'ramda/src/isEmpty'
import { peopleSearch } from './api'
const showNoSearch = $`No search was performed.`
const showNoResults = search => () => `0 Results for "${search}".`
const showResults = W (({ length }) => pipe ([
map ($`- ${'name'} (${'gender'})`),
join ('\n'),
prepend (`${length} results:\n`)
]))
const ifEmpty = ifElse (isEmpty)
const searchForPerson = axios => W (search => pipe ([
peopleSearch (axios),
ifEmpty (showNoResults (search)) (showResults)
]))
const main = ({ axios, askQuestion, log }) => pipe ([
askQuestion ('Search for Star Wars Character: '),
ifEmpty (showNoSearch) (searchForPerson (axios)),
log
])
export default main