Re: [ANN] LPredicate - Library for composing predicates
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [ANN] LPredicate - Library for composing predicates
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: 2014年3月28日 10:32:58 +0800
On 03/28/2014 06:42 AM, Elias Barrionovo wrote:
This is a quick hack based on something I once had to do in Python,
because Lua didn't have overloadable bitwise ops... until now! =D
Lpredicate allows the building of boolean expressions on predicates,
wich are basically lua functions wrapped as tables with some bitwise
ops:
--
even = predicate(function (n) return n % 2 == 0 end)
greater100 = predicate(function (n) return n > 100 end)
(even & greater100)(150) --> true
(even & greater100)(80) --> false
(even & ~greater100)(80) --> true
--
Code can be found at github: https://github.com/etandel/lpredicate
seems interesting.
I'll check it so see whether I can integrate that into my unit testing infrustructure.
but firstly, I should test my code under Lua 5.3 :)