-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathifElse.mjs
33 lines (25 loc) · 857 Bytes
/
ifElse.mjs
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
33
import log from 'mojiscript/console/log'
import pipe from 'mojiscript/core/pipe'
import run from 'mojiscript/core/run'
import ifElse from 'mojiscript/logic/ifElse'
import $ from 'mojiscript/string/template'
const dependencies = {
log
}
const state = [ 1, 2, 3 ]
// hasOrders :: Array -> Boolean
const hasOrders = ({ length }) => length > 0
// orderCountText :: Array -> OrdersString
const orderCountText = $`${'length'} orders`
// noOrderCountText :: * -> OrdersString
const noOrderCountText = $`No Orders`
// ifHasOrders :: Function -> Function
const ifHasOrders = ifElse (hasOrders)
// getOrdersText :: (a -> b) -> (a -> b) -> OrdersString
const getOrdersText = ifHasOrders (orderCountText) (noOrderCountText)
// main :: Number -> String
const main = ({ log }) => pipe ([
getOrdersText,
log
])
run ({ dependencies, state, main }) //= > 'NO'