unparse static method

int unparse(
  1. Iterable<bool> week
)

Encodes the booleans into a bitfield. The length of week should be 7. week is expected to be little-endian with true indicating the presence of a day.

That is so say, the first element in week will represent whether Monday is present. For example, [true, false, false true, false, false, false] will indicate that Monday and Thursday is present.

Behaviour is undefined if the given week is invalid.

Implementation

static int unparse(Iterable<bool> week) {
  assert(week.length == 7, 'Number of days is "${week.length}", should be 7');
  var encoded = 0;
  for (final day in week.toList().reversed) {
    encoded <<= 1;
    if (day) {
      encoded += 1;
    }
  }

  return encoded;
}