Flags (ex_esdb v0.0.5-alpha)
This module is used to manipulate bitwise flags.
Inspired by: Flags in C#
Event souurced systems often rely on flags to indicate the state of the aggregate at any given time. In this module, we define a set of functions that can be used to manipulate these flags.
Summary
Functions
Returns the bitwise OR of two flags.
In other words, it sets the bit that corresopnds to the flag
GIVEN: original_state is 0b00100100
(integer: 36)
WHEN the flag to be set is 0b01000000
(integer: 64)
THEN the result is 0b01100100
(integer: 100)
Returns the bitwise OR of multiple flags against a given state.
In other words, it sets the bits that corresopnds to the flags
GIVEN: original_state is 0b00100100
(integer: 36)
WHEN the flags to be set are [0b01000000, 0b10000000]
(integers: 64, 128)
THEN the result is 0b11100100
(integer: 228)
Returns the bitwise AND of two flags.
In other words, it unsets the bit that corresopnds to the flag
GIVEN: original_state is 0b01100100
(integer: 100)
WHEN the flag to be unset is 0b01000000
(integer: 64)
THEN the result is 0b00100100
(integer: 36)
Functions
Returns the bitwise OR of two flags.
In other words, it sets the bit that corresopnds to the flag
GIVEN: original_state is 0b00100100
(integer: 36)
WHEN the flag to be set is 0b01000000
(integer: 64)
THEN the result is 0b01100100
(integer: 100)
Example: iex> Flags.set(36, 64) 100
Returns the bitwise OR of multiple flags against a given state.
In other words, it sets the bits that corresopnds to the flags
GIVEN: original_state is 0b00100100
(integer: 36)
WHEN the flags to be set are [0b01000000, 0b10000000]
(integers: 64, 128)
THEN the result is 0b11100100
(integer: 228)
Example: iex> Flags.set_all(36, [64, 128]) 228
Returns the bitwise AND of two flags.
In other words, it unsets the bit that corresopnds to the flag
GIVEN: original_state is 0b01100100
(integer: 100)
WHEN the flag to be unset is 0b01000000
(integer: 64)
THEN the result is 0b00100100
(integer: 36)
Example: iex> Flags.unset(100, 64) 36