Skip to content

Commit 9476d1c

Browse files
committed
more functional way
1 parent b9a4177 commit 9476d1c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

interpret.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const {
22
append, apply, curryN, filter,
3-
head, isArrayLike, length, map,
4-
merge, nth, pipe, replace,
3+
head, isArrayLike, join, length,
4+
map, merge, nth, pipe, replace,
55
split, tail, trim, values,
66
zipObj
77
} = require('ramda')
@@ -44,7 +44,9 @@ const evaluate = curryN(2, (env, x, defName) => {
4444
return apply(evaluate(env, name), map(evaluate(env), rest))
4545
})
4646

47-
const exprToString = (expr) => `(${map((e) => isArrayLike(e) ? exprToString(e) : e, expr).join(' ')})`
47+
const wrap = curryN(3, (start, end, value) => start + value + end)
48+
49+
const exprToString = pipe(map((exp) => isArrayLike(exp) ? exprToString(exp) : exp), join(' '), wrap('(', ')'))
4850

4951
const la = pipe(parse, map(evaluate({})))
5052

0 commit comments

Comments
 (0)