Conversation
| export function List$NonEmpty<T>(head: T, tail: List<T>): List<T>; | ||
| export function List$isEmpty<T>(list: List<T>): boolean; | ||
| export function List$isNonEmpty<T>(list: List<T>): boolean; | ||
| export function List$isEmpty(list: any): boolean; |
There was a problem hiding this comment.
You can write this as:
export function List$isEmpty(list: any): list is List<unknown>...and the same for the other guard functions.
This lets typescript actually refine the type of a value based on the guard.
There was a problem hiding this comment.
Shouldn't List$isEmpty take a List as an argument though? Or is the api supposed to work no matter what we pass to the function?
There was a problem hiding this comment.
It needs to take any otherwise we can't use these functions for dynamic.classify or string.inspect
There was a problem hiding this comment.
Does that still effectively return a boolean @hayleigh-dot-dev ?
There was a problem hiding this comment.
Does it look right to you now @hayleigh-dot-dev ?
|
Does that mean all the properties/getters on BitArray should be considered private? |
Yes, everything not in the documented public API is private. |
|
I think there's no way to work with non-byte-aligned/non-zero bitSizes then? |
|
@yoshi-monster @richard-viney How could unaligned bit arrays be used at all in JavaScript? The language doesn't have any capability to work with data like that, that I'm aware of. I couldn't think of a design that would provide something that wouldn't be replicating the functionality they have in the Gleam language, and if they can do it in Gleam without loss of performance (or some other drawback) then I don't want to encourage doing it with FFI instead. |
I have to admit every time I FFI to BitArrays I always assert they are byte-aligned, I think my initial reaction was just based on feeling there should be a way to do this without a concrete use-case in mind. |
I think the only sensible use case for FFI is conversion to a Uint8Array / DataView etc. My suggestion would be:
export const BitArray$BitArray$data = (bitArray) => {
if (bitArray.bitSize % 8 !== 0) {
throw Error("Bit arrays that aren't a whole number of bytes can't be read in JavaScript");
}
let array = bitArray.rawBuffer;
if (bitOffset !== 0) {
array = new Uint8Array(bitArray.byteSize);
for (let i = 0; i < array.length; i++) {
array[i] = bitArray.byteAt(i);
}
}
return new DataView(array.buffer, array.byteOffset, array.byteLength);
}; |
No description provided.