4 ms·
Sorry I don't understand what you built, but it seems interesting, can you please explain it in plain English.
by iduy 10y ago
Sorry I don't understand what you built, but it seems interesting, can you please explain it in plain English.
- agentultra 10y agoSure! The problem I need to solve is to add an authorization system to our stack. Because we need to support a good number of authorization scenarios the system needs to be flexible. So I wrote an expression parser that takes an "authorization expression" in my input language and outputs a function. That function takes the authorization context and either returns a Success value or a list of Failure. The pattern I'm using to generate that function is called a "Validation." It's a kind of applicative functor which is essentially a list of functions we map over. The result is the success value or a semi-group of the failed functions. All my expression parser has to do is generate the "list of functions" to feed into the Validation. This is really cool because now I can write very expressive authorization clauses and it always generates a nice function that either passes or gives the user a nice list of the exact conditions that failed. It's a surprisingly small amount of code for such a handy tool... Which means it's simple in the sense that it's precise and succinct. Savvy? I took some liberties with the definition of what an applicative functor is. If you're interested there are a great number of resources to learn about them and I encourage everyone to read up and try to understand the true definition themselves.
- gandolfinmyhead 10y agosooo :: Foldable b => String -> (a -> Either a b)