funcool / lentes

Functional references for Clojure and ClojureScript
https://cljdoc.org/d/funcool/lentes/CURRENT
BSD 2-Clause "Simplified" License
94 stars 10 forks source link

content.adoc Composition example gets "nth not supported on this type: Long" error #9

Closed wrightmikea closed 1 month ago

wrightmikea commented 7 years ago

When I evaluate the composition example (using cider nrepl) I get an "nth not supported on this type: Long" error.

user> (require '[lentes.core :as l]) nil user> (def my-lens (comp l/fst l/fst (l/nth 2)))

'user/my-lens

user> (def data [[0 1 2] [3 4 5]])

'user/data

user> (l/focus my-lens data) UnsupportedOperationException nth not supported on this type: Long clojure.lang.RT.nthFrom (RT.java:888) user>

Either my-lens should have one fewer l/fst function in the composed function or the data needs another level of square brackets, right?

This works for me:

user> (def my-lens2 (comp l/fst (l/nth 2)))

'user/my-lens2

user> (l/focus my-lens2 data) 2 user> (def data2 [[[0 1 2] [3 4 5]]])

'user/data2

user> (l/focus my-lens data2) 2 user>

aiba commented 1 month ago

There was a typo in the docs. It's now fixed by #14