top | item 43297472 Functional vs. Data-Driven Development: A Case-Study in Clojure and OCaml 6 points| gopiandcode | 1 year ago |kirancodes.me 1 comment order hn newest artikae|11 months ago assoc-in reminds me a lot of lenses in Haskell. I figure you could probably implement something like it using them. This is what I came up with: import Control.Lens baseLens --> nextIndex = baseLens . ix nextIndex assocIn structure keyLens newValue = set keyLens newValue structure It works like so: setTo256 structure = assocIn structure (ix 0 --> 0 --> 0) 256 -- setTo256 [[[1]], [[2]]] returns [[[256]], [[2]]]
artikae|11 months ago assoc-in reminds me a lot of lenses in Haskell. I figure you could probably implement something like it using them. This is what I came up with: import Control.Lens baseLens --> nextIndex = baseLens . ix nextIndex assocIn structure keyLens newValue = set keyLens newValue structure It works like so: setTo256 structure = assocIn structure (ix 0 --> 0 --> 0) 256 -- setTo256 [[[1]], [[2]]] returns [[[256]], [[2]]]
artikae|11 months ago