squint-cljs / squint

Light-weight ClojureScript dialect
https://squint-cljs.github.io/squint
587 stars 35 forks source link

Support keywords as functions in higher order functions #507

Closed benjamin-asdf closed 3 months ago

benjamin-asdf commented 3 months ago

(juxt :id identity)

this becomes squint_core.juxt("id", squint_core.identity)

Could it support keyword functions?

benjamin-asdf commented 3 months ago

Also maps and so forth as functions? I guess that implies passing around some callable object.

borkdude commented 3 months ago

I looked into it and juxt already supports "keyword functions". In squint keywords simply translate to strings. In squint's version of juxt, strings are interpreted as lookup functions:

$ ./node_cli.js --show -e '(js/console.log ((juxt :foo :bar) {:foo 1 :bar 2}))'
import * as squint_core from 'squint-cljs/core.js';
console.log(squint_core.juxt("foo", "bar")(({ "foo": 1, "bar": 2 })));

[ 1, 2 ]