Originally published at deepu.tech.
There is a lot of hype around functional programming(FP) and a lot of cool kids are doing it but it is not a s...
For further actions, you may consider blocking this person and/or reporting abuse
Hi there, great article! Did you know that you can use
Object.freeze
to prevent mutating an array or an object?It will couse runtime exception. So Object.freeze is not useful in terms of TS.
Hi Maciej. You are absolutely right! That's why it is so good coupled with TypeScript which can prevent mutating a freezed object by refusing to transpile the file.
Still I see
readonly
as a tool for the job.Object.freeze
is fully run-time thing and it is decoupled from type definition. Declaration ofreadonly
is included into type definition, so it is explicit. I don't think run-time block is needed here.Yes, I thought of writing about it but then missed
or
Mutation doesn't affect referential transparency - reference stays the same.
I have updated the post
Yes, I missed that
Hi! It may be worth mentioning that
"TypeScript comes with a ReadonlyArray type that is the same as Array with all mutating methods removed, so you can make sure you don’t change your arrays after creation"
typescriptlang.org/docs/handbook/i...
Oh yes, I completely forgot about those
Stack, Map and Queue are not data types related to FP, they have FP implementations, but still the sentence is wrong.
I have rephrased it
Sure they are not related to FP, what I meant was that they are more appropriate for the FP approach
Virtually everywhere you say "TypeScript", you seem to mean "JavaScript". It is not TypeScript that treats functions as first-class objects, or lazily evaluates boolean expressions. It's JavaScript. TypeScript is merely JavaScript with type annotations.
Yes, and thats why I keep saying typeScript/JavaScript and also I made it clear in the beginning that TS is just a superset of JS
What kind of markdown do you use to link to the other articles at the top? It looks neat!
Its the series feature in Dev, if you add
series: my series name
to the front matter of the post-it links them up that way