Fun of clojure - wrap some code around data

submited by
Style Pass
2021-06-15 19:30:07

Recently FOMO got to me and I jumped on crypto speculation game. You gots to do bunch of accounting/counting/reconciling/tracking in it. Sounds boring, but clojure made it fun. And that’s what I want to share here.

There’s plenty of portfolio tracking tools on the nets. If it wasn’t for clojure I would go for one of those and would reluctantly give-out info about my trades to a third party. Rather that though than teaching C# or java compiler about structure of my data with classes/structs so that I can start deriving info from it. Even with dynamic Python it would be a hassle.

Instead of waxing poetic about simplicity, I would best describe hacking on clojure as “wrap some code around data”. Let me illustrate: in my crypto game, I have a bunch of transactions - facts about buying/selling cryptos and deposits I sent into the exchange. When I make a transaction I append it to an EDN file “transactions.edn”:

It’s a map with 3 kinds of transactions: :deposit :buy :sell. Transaction is an array (vector) that has a tag of a crypto, amount and price. Dates are metadata about my transactions and clojure has a notion of metadata built-in, you can attach it to the peace of data (like an array), read it when you want it, but keep it out of the way of calculations.

Leave a Comment