-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] add support for TypedArrays/arrayBuffer/nodejs' Buffer #716
base: main
Are you sure you want to change the base?
[WIP] add support for TypedArrays/arrayBuffer/nodejs' Buffer #716
Conversation
Currently failing to implement tests for TypedArray. In `assert.strictEqual (equals (actual) (expected), true);` the `Setoid.test` test fails unconditionaly for a TypedArray (`Uint8Array`). Need help ;)
I don't think this makes sense. Here is the type of take :: (Applicative f, Foldable f, Monoid (f a)) => Integer -> f a -> Maybe (f a) We could specialize this by replacing take :: Integer -> Array String -> Maybe (Array String) Doing the same with take :: Integer -> Uint8Array String -> Maybe (Uint8Array String)
One could define a specialized function: takeUint8 :: Integer -> Uint8Array -> Maybe Uint8Array |
@davidchambers How would I go about implementing specialised functions for Sanctuary? Would takeTypedArray :: Integer -> TypedArray -> Maybe TypedArray |
The hypothetical The simplest solution would be to define a specialized function for each type. |
So that would be 11 specialized functions, just for takeInt8Array :: Integer -> Int8Array -> Maybe Int8Array takeUint8Array :: NonNegativeInteger -> Uint8Array -> Maybe Uint8Array takeUint8ClampedArray :: NonNegativeInteger -> Uint8ClampedArray -> Maybe Uint8ClampedArray takeInt16Array :: Integer -> Int16Array -> Maybe Int16Array takeUint16Array :: NonNegativeInteger -> Uint16Array -> Maybe Uint16Array takeInt32Array :: Integer -> Int32Array -> Maybe Int32Array takeUint32Array :: NonNegativeInteger -> Uint32Array -> Maybe Uint32Array takeFloat32Array :: ValidNumber -> Float32Array -> Maybe Float32Array takeFloat64Array :: ValidNumber -> Float64Array -> Maybe Float64Array Does Sanctuary support BigInt? takeBigInt64Array :: BigInt -> BigInt64Array -> Maybe BigInt64Array takeBigUint64Array :: NonNegativeBigInt -> BigUint64Array -> Maybe BigUint64Array But actually, before going down this rabbit hole. I'm much more interested in support for Nodejs' Buffer since I deal with a database that returns Buffers. takeBuffer :: NonNegativeInteger -> Buffer -> Maybe Buffer
dropBuffer :: NonNegativeInteger -> Buffer -> Maybe Buffer
takeLastBuffer :: NonNegativeInteger -> Buffer -> Maybe Buffer
dropLastBuffer :: NonNegativeInteger -> Buffer -> Maybe Buffer
takeWhileBuffer :: (a -> Boolean) -> Buffer -> Buffer
dropWhileBuffer :: (a -> Boolean) -> Buffer -> Buffer Ref: NonNegativeInteger |
I tried to look through some code a few months back to find context for this. I did not find anything. But as I recall, I got a Buffer from the database and wanted to use Changing that one line, made it all work in Sanctuary but .... here I am. |
If I'd want to // firstFiveBytes :: Buffer -> Maybe Buffer
const firstFiveBytes = S.pipe ([
Array.from,
S.take (5),
S.map (Buffer.from),
]) |
@Avaq I'm imagining that working with Buffers without converting them to Array would be faster overall. But I should write some code to compare with. There is only one line that need to change in Sanctuary in order to support Buffers, so it should be fairly easy to compare. But it won't be today :) |
Currently failing to implement tests for TypedArray.
In
assert.strictEqual (equals (actual) (expected), true);
theSetoid.test
test fails unconditionaly for a TypedArray (Uint8Array
).Need help ;)
Reproduce:
PS. For now my goal is to support various Buffers for
unchecked
functions, since it seems like this should be opt-in and I don't know how to implement support in https://github.com/sanctuary-js/sanctuary-def yet.