Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
prelude.ts
Advanced tools
Prelude.ts is a typescript library which aims to make functional programming concepts accessible and productive in typescript.
It provides immutable collections (Vector, Set, Map, Stream), and constructs such as Option.
Vector.of(1,2,3)
.map(x => x*2)
.head()
// => Option.of(2)
Option.sequence(
Vector.of(Option.of(1), Option.of(2)))
// => Option.of(Vector.of(1,2))
Vector.of(1,2,3,4).groupBy(x => x%2)
// => HashMap.empty().put(0, Vector.of(2,4)).put(1, Vector.of(1,3))
Vector.of(1,2,3).zip("a", "b", "c").takeWhile(([k,v]) => k<3)
// Vector.of([1,"a"],[2,"b"])
The collections are also javascript iterables, so if you have an ES6 runtime,
you can use the for .. of
construct on them.
You can check the tests for examples of use, and browse the API documentation.
At this time most of the collections are implemented using the HAMT algorithm, and concretely the hamt_plus library. Besides this dependency, I'll try to limit the number of dependencies. In addition the library is written in idiomatic javascript style, with loops instead of recursion, so the performance should be reasonable.
Javascript doesn't have structural equality, except for primitive types.
So, 1 === 1
is true. But [1] === [1]
is not, and neither {a:1} === {a:1}
.
This poses problems for collections, because if you have a Set
, you don't
want duplicate elements because of this limited definition of equality.
For that reason, prelude.ts encourages you to define for your non-primitive types
methods equals(other: any): boolean
and hashCode(): number
(the same
methods that immutable.js uses).
With these methods, structural equality is achievable, and indeed
Vector.of(1,2,3).equals(Vector.of(1,2,3))
is true
. However this can only
work if the values you put in collections have themselves properly defined equality
(see how prelude.ts can help).
If these values don't have structural equality, then we can get no better than
===
behavior.
prelude.ts attempts to assist the programmer with this; it tries to encourage
the developer to do the right thing. First, it'll refuse types without properly
defined equality in Sets and in Maps keys. Second, it has a special terminology
for types without properly defined equality: 'structs'.
When you operate with for instance a Vector
, you'll have to explicitely say
when you deal with structs. So Vector.of([1])
will not compile.
You get (a longer version of) this message:
Type 'number[]' is not assignable to type 'HasEquals'.
Property 'equals' is missing in type 'number[]'.
So the solution is to use a struct-oriented function: Vector.ofStruct([1])
.
That version compiles just fine. But now you've been warned that you can't use
this value in a Set or as a Map key, and that equality features are not provided.
Similary, functions such a map
have alternate implementations such as mapStruct
to warn the programmer in these cases.
I think these concepts are not expressible in a good enough manner on a language such as typescript.
List
and
Option
collections, implemented in functional-style ES5.Option
concept, the types can be clunky.R.filter(R.where(...))
while prelude.ts prefers a
fluent-api style like list.filter(..).sortBy(...)
npm install
npm test
npm run-script docgen
npm run benchmarks
FAQs
A typescript functional programming library
The npm package prelude.ts receives a total of 13 weekly downloads. As such, prelude.ts popularity was classified as not popular.
We found that prelude.ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.