@Bravilogy I use them for a permissions system in my api. When I do it in JS I use a library I wrote: https://www.npmjs.com/package/flagon to make it seem less arcane.
In postgres, I use operators like bit_or.
You can do cool stuff like:
var auth_permissions_read = group_permissions.reduce( flagon.merge, 0)
And in sql:
coalesce(
bit_or(
case when GE.group_permissions_read
then P.permission_flag else 0
end
)
,0
) as auth_permissions_read
I prefer not to use |
/ &
directly, because its not immediately obvious to other people on the team that they aren't meant to be ||
or &&
.
And in some cases, its super hard to read e.g. flagon.contains
equates to: B == 0 || ((A & B) == B)
merge
be OR.concat
and toggle
could be XOR.concat
etc
const OR = {
of: a => ({
fold: () => a
,toString: () => [
'OR(0b',a.toString(2),')'
].join('')
,concat: b => OR.of(b.fold() | a)
})
,concat: (a,b) => a.concat(b)
,empty: () => OR.of(0)
}
var f = pipe(
map(OR.of)
,reduce(OR.concat, OR.empty())
)
f([0b001, 0b010, 0b100])
//=> 0b111
{{{ }}}
and text is stored as plan text
some string with placeholders
"
const text = `
Demo variable = {{{demo}}}
Foo = {{{foo}}}
`;
const vars = {
demo: 'I m demo!',
foo: 'fooVar'
};
text.replace(/{{{(\w+)}}}/g, function (match, key) {
return vars[key];
});
//=> "\n Demo variable = I m demo! \n Foo = fooVar\n”
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement.
const ary2 = R.pipe(R.nAry(2), R.curry);
const testPermissionsPath = testPath(['settings', 'permissions']);
const testPermissionsAnd = R.useWith(R.both, [R.identity, testPermissionsPath]);
const filterRouteBy = ary2(R.pipe(testPermissionsAnd, R.filter));
const filterByPermissionsTestAnd = R.pipe(filterRouteBy, R.uncurryN(2));
(isNavBarRoute) => (hasSomePermissions) => (routes) => (filteredRoutes)
=D
useWith
, that is what I needed yesterday! ;)
pick([1,3,5], Buffer("af3de4d60935f3", "hex")) === Buffer("3dd635", "hex")