Skip to content

Commit

Permalink
Simplify join bits function.
Browse files Browse the repository at this point in the history
Use reduce from itertools instead of for.
  • Loading branch information
denpamusic committed Oct 24, 2023
1 parent efb3426 commit 36691fa
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pyplumio/structures/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections.abc import Sequence
from dataclasses import dataclass
from functools import reduce
from itertools import chain
from typing import TYPE_CHECKING, Final

Expand Down Expand Up @@ -135,11 +136,7 @@ def _split_byte(byte: int) -> list[bool]:

def _join_bits(bits: Sequence[int | bool]) -> int:
"""Join eight bits into a single byte."""
result = 0
for bit in bits:
result = (result << 1) | bit

return result
return reduce(lambda x, y: (x << 1) | y, bits)


class SchedulesStructure(Structure):
Expand Down

0 comments on commit 36691fa

Please sign in to comment.