As a Python person, that 2nd one looks like a bug. Expecting an exception there. Although also Python doesn't have an `undefined`; `None` would have to suffice.
Not really. If you try to take something from an empty container (language or real life) then you should get an error/issue. The container type doesn't change when it's empty, and the operation is just senseless; all that's happening here is added mental gymnastics that makes code unintuitive to read. Checking if/asserting a container isn't empty is a straight forward `if cont: ...` or `assert cont` in Python, which anyone can just get.
The type soft-enforces₁ it immediately for everyone though.
Without the type there are a few possibilities:
1. I could forget the assertion and have buggy code without realizing.
2. I could ensure that all uses do the assertion. Even if we can statically know that it is empty. This costs us the check for every call of the function, and ends up being more code.
Alternatively I could statically know in advance. The code won't let me `Array.pop` because that is invalid, so:
1. I *cannot* make that mistake
2. It cost no runtime performance
3. It cost no extra code in a function
1: I say soft-enforce because if someone were to pass a value incorrectly cast as NonEmpty, it would still have a runtime error, but that is a bug elsewhere, not here.
claude-ai · · focus · HN ↗
slopinthebag · · focus · HN ↗
nvme0n1p1 · · focus · HN ↗
Rebuild JS's core data structures: <a href="https://effect.website/docs/v4/api/effect/Array" rel="nofollow">https://effect.website/docs/v4/api/effect/Array
Then rebuild the entire JS ecosystem on top of their custom data structures.
And then the main heading on their home page is "Reliable TypeScript for the AI era"? Really? I'll pass.
maleldil · · focus · HN ↗
> Works with JavaScript arrays
nvme0n1p1 · · focus · HN ↗
slopinthebag · · focus · HN ↗
"Use when you need to guarantee a non-empty result after adding a required trailing value."
...whatever that means lol
itishappy · · focus · HN ↗
skeledrew · · focus · HN ↗
spaethnl · · focus · HN ↗
skeledrew · · focus · HN ↗
spaethnl · · focus · HN ↗
Without the type there are a few possibilities: 1. I could forget the assertion and have buggy code without realizing. 2. I could ensure that all uses do the assertion. Even if we can statically know that it is empty. This costs us the check for every call of the function, and ends up being more code.
Alternatively I could statically know in advance. The code won't let me `Array.pop` because that is invalid, so:
1: I say soft-enforce because if someone were to pass a value incorrectly cast as NonEmpty, it would still have a runtime error, but that is a bug elsewhere, not here.