sum-types
immutable-js
sum-types | immutable-js | |
---|---|---|
8 | 38 | |
42 | 32,867 | |
- | 0.1% | |
5.9 | 7.0 | |
3 months ago | 19 days ago | |
TypeScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
sum-types
-
Either type
I entirely agree about using symbols. sum-types does that.
-
Question about error handling in Typescript
With fp-ts and sum-types you'd handle this functionally like so:
-
type .kind checks vs. class instanceof checks
If you're looking to have discriminated unions like Rust, follow that section to roll your own or look for a library that's already implemented them. fp-ts has everything under the sun in a Haskell style, neverthrow has Rust-like Result and ResultAsync, and sum-types helps with the boilerplate of defining your own sum types.
-
Is there a more graceful way to create dependencies between object key settings?
I'd suggest sum-types. Instead of unsafe user-defined type guards you get safe pattern matching.
-
Best way to store persistent texts?
If you wanted to lean (more) into FP you could replace the Event type and buildPopup function with a sum type and pattern match respectively, as well as represent side effects like in popup with fp-ts' IO, make use of function composition, etc. The former in particular is great for readability:
-
Is there any known way to measure coverage of... types?
You can test types, at least in terms of asserting happy path types and whether a piece of code, runtime or purely type-level, should trigger a tsc type error. Here's an example using eslint-plugin-expect-type.
-
Has the unsoundness (will explain in the post) actually become a pitfall in practice?
Anywhere that overloads are needed will rely upon type assertions or the unsafety implicit in overloads, for example in fp-ts/function::pipe. It'll come up a lot with objects too when there isn't a preexisting primitive you can compose atop of, as in for example fp-ts-std/Record::pick. Something as generic as @unsplash/sum-types has assertions all over the place, though to be fair that's mostly again a case of struggles interacting with object types.
-
How to handle "mutable state" in a pure functional way
You might like @unsplash/sum-types also.
immutable-js
-
Yet another introduction to Functional Programming
immutable for JavaScript.
-
Imutability, react and typescrip: how to do it the clean way?
Check out Object.freeze. There's also Immutable.js for working with immutable data.
-
How To Scale Your React Applications
Use immutability to manage state updates When updating state in your React application, it's important to ensure that you are not mutating the original state object. Instead, you should create a new copy of the state object with the updated values. Immutability makes it easier to manage state updates and ensures that the updates are performed in a predictable and safe manner. Libraries like Immutable.js provide a set of functions that simplify working with immutable data in React applications.
-
Is it possible to strongly type properties of class dynamically added in the constructor?
We're wanting to get rid of immutable so I'm trying to replicate what it is about the Record functionality and types that allow this dynamic property access to work. After pulling my hair out looking through the [email protected] type definitions and the actual code, to me it looks like the types are just kind of lying about what's going on ... and it's just working. Does anyone have any ideas how I can replicate this dynamic property access with strong typings?
-
Functional immutable game state
The Immutable.js README has a much more complete description of immutability and why you might want to use the library. Also worth mentioning that Immer is an alternative which is a bit easier to get started with.
-
"console.log" Sometimes Print Wrong Data
Examples: immutable-js Immer
-
Immutable Collections should be Your Default
I can't speak to C# and Java, but the suggestion in this post: ImmutableJS already uses Persistent data structures. (It's the second sentence of their introduction)
-
How do I type reduce when Im reducing an array to count elements?
Avoiding mutation is just never modifiyng an object, ever. There are tons of implementations of this pattern, notably immutable.js (https://immutable-js.com/), Redux is also an example of this philosophy.
-
Alan Perlis and the Evolution of Programming Languages
JavaScript is most programers' first introduction to map, filter, and reduce. Easy lambdas made those higher-order functions a staple of a lot of JS code.
Meanwhile, immutable.js[0] is at 10 million downloads per week and rising.
I would add that it's not just the ease of use of lambdas, but the fact that in JavaScript functions really are first class citizens. Most of the other widely used languages that people start on have lambda functions added in as a bit of a hack and only treat some functions as real values.
[0] https://www.npmjs.com/package/immutable
-
immutable-js VS riux - a user suggested alternative
2 projects | 12 Aug 2022
What are some alternatives?
TypeScript - TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Immer - Create the next immutable state by mutating the current one
tsd - Check TypeScript type definitions
mori - ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript
nominal - Powerful nominal types for your Typescript project
ramda - :ram: Practical functional Javascript
lodash - A modern JavaScript utility library delivering modularity, performance, & extras.
eslint-plugin-expect-type - ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩
RxJS
Visual Studio Code - Visual Studio Code
immutability-helper - mutate a copy of data without changing the original source