Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using monads to do failable transformations in bulk?

Just starting to grok monads. I think in Clojure, so purity isn't terribly important to me.

I have a series of business operations (composable transforms) which may fail. This can be abstracted nicely with error-monad.

Some of the business operations involve database IO, and I need to perform the operations in bulk for speed. each bulk operation acts on a set of independent items, so one failure must not fail the whole set.

should I just think of my bulk transforms as a series of functions on one object (map) done inside something like error monad but acting on independent items in a seq? does seq-monad help me here? how should I be thinking about this? any other ideas?

I don't see any particular benefit in combining this with IO-monad for my database side effects in Clojure, thoughts on this?

like image 585
Dustin Getz Avatar asked Nov 13 '22 07:11

Dustin Getz


1 Answers

It's hard to say what you need exactly, because your business case seems a little involved, but I think you may get some mileage from using the clojure.algo.monads library.

You can create your own variation on a error-monad or maybe-monad that internally deals with batches.

like image 180
Alex Baranosky Avatar answered Feb 20 '23 09:02

Alex Baranosky