mori
sum-types
Our great sponsors
mori | sum-types | |
---|---|---|
5 | 8 | |
3,388 | 42 | |
- | - | |
0.0 | 5.9 | |
about 4 years ago | 2 months ago | |
Clojure | TypeScript | |
- | 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.
mori
-
Om but in javascript
immutable-js or mori for immutable data structures
-
How to handle "mutable state" in a pure functional way
Use persistent immutable data structures (as implemented in, for instance, mori or Immutable.js) to represent the state. As much as possible, push calculations into referentially transparent functions (i.e., input depends purely on output) which take persistent data. Write the interactions with the real world in imperative style.
- Understanding Clojure's Persistent Vectors (2013)
-
Immutable.js is not dead!
Mori
-
Functional Programming with Javascript | Introduction
Always make immutable variables. You can achieve this by having a persistence data structure using Mori or immutable.js libraries to open the features such as linked list, trees, path dealing to help with efficiency. I will not be covering how to create a persistence data structure using those libraries as it’s not the scope of this post.
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.
What are some alternatives?
immutable-js - Immutable persistent data collections for Javascript which increase efficiency and simplicity.
TypeScript - TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Immer - Create the next immutable state by mutating the current one
ramda - :ram: Practical functional Javascript
tsd - Check TypeScript type definitions
lodash - A modern JavaScript utility library delivering modularity, performance, & extras.
nominal - Powerful nominal types for your Typescript project
underscore-contrib - The brass buckles on Underscore's utility belt
eslint-plugin-expect-type - ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩
buckets - A complete, fully tested and documented data structure library written in pure JavaScript.
Visual Studio Code - Visual Studio Code