Skip to content

Commit f4511c5

Browse files
committed
minor refactor
1 parent 1c80d72 commit f4511c5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/gleam_stdlib.mjs

+6-8
Original file line numberDiff line numberDiff line change
@@ -455,17 +455,15 @@ export function bit_array_split_once(bits, pattern) {
455455

456456
export function bit_array_split(bits, pattern) {
457457
try {
458-
if (!(bits instanceof BitArray)
459-
|| !(pattern instanceof BitArray)
460-
|| pattern.buffer.length < 1) {
458+
const patternEmpty = pattern.buffer.length < 1
459+
const incorrectArguments = !(bits instanceof BitArray) || !(pattern instanceof BitArray)
460+
if (incorrectArguments || patternEmpty) {
461461
return new Error(Nil);
462462
}
463463

464-
if (bits.buffer.length === 0) {
465-
return new Ok(List.fromArray([]));
466-
}
467-
468-
if (Buffer.compare(bits.buffer, pattern.buffer) === 0) {
464+
const bitsEqualToPattern = Buffer.compare(bits.buffer, pattern.buffer) === 0
465+
const bitsEmpty = bits.buffer.length === 0
466+
if (bitsEqualToPattern || bitsEmpty) {
469467
return new Ok(List.fromArray([]));
470468
}
471469

0 commit comments

Comments
 (0)