1
- # prelude. ts
1
+ # prelude- ts
2
2
[ ![ NPM version] [ npm-image ]] [ npm-url ]
3
3
[ ![ Tests] [ circleci-image ]] [ circleci-url ]
4
4
[ ![ apidoc] [ apidoc-image ]] [ apidoc-url ]
5
5
6
6
## Intro
7
7
8
- Prelude. ts is a typescript library which aims to make functional programming
8
+ prelude- ts is a typescript library which aims to make functional programming
9
9
concepts accessible and productive in typescript. Note that even though it's
10
10
written in typescript, it's perfectly usable from javascript (including ES5)!
11
11
@@ -53,7 +53,7 @@ and concretely the [list library](https://github.com/funkia/list/), as of 0.7.7.
53
53
In addition the library is written in idiomatic javascript style, with loops
54
54
instead of recursion, so the performance should be good
55
55
([ see benchmarks here comparing to immutable.js and more] ( https://github.com/emmanueltouzery/prelude.ts/wiki/Benchmarks ) ).
56
- ` list ` and ` hamt_plus ` are the two only dependencies of prelude. ts.
56
+ ` list ` and ` hamt_plus ` are the two only dependencies of prelude- ts.
57
57
58
58
## Set, Map and equality
59
59
@@ -62,17 +62,17 @@ So, `1 === 1` is true. But `[1] === [1]` is not, and neither `{a:1} === {a:1}`.
62
62
This poses problems for collections, because if you have a ` Set ` , you don't
63
63
want duplicate elements because of this limited definition of equality.
64
64
65
- For that reason, prelude. ts encourages you to define for your non-primitive types
65
+ For that reason, prelude- ts encourages you to define for your non-primitive types
66
66
methods ` equals(other: any): boolean ` and ` hashCode(): number ` (the same
67
67
methods that [ immutable.js uses] ( https://facebook.github.io/immutable-js/docs/#/ValueObject ) ).
68
68
With these methods, structural equality is achievable, and indeed
69
69
` Vector.of(1,2,3).equals(Vector.of(1,2,3)) ` is ` true ` . However this can only
70
70
work if the values you put in collections have themselves properly defined equality
71
- ([ see how prelude. ts can help] ( https://github.com/emmanueltouzery/prelude.ts/wiki/Equality ) ).
71
+ ([ see how prelude- ts can help] ( https://github.com/emmanueltouzery/prelude.ts/wiki/Equality ) ).
72
72
If these values don't have structural equality, then we can get no better than
73
73
` === ` behavior.
74
74
75
- prelude. ts attempts to assist the programmer with this; it tries to encourage
75
+ prelude- ts attempts to assist the programmer with this; it tries to encourage
76
76
the developer to do the right thing. First, it'll refuse types without obviously properly
77
77
defined equality in Sets and in Maps keys, so ` HashSet.of([1]) ` ,
78
78
or ` Vector.of([1]).equals(Vector.of([2])) ` will not compile.
@@ -82,7 +82,7 @@ For both of these, you get (a longer version of) this message:
82
82
Property 'equals' is missing in type 'number[]'.
83
83
84
84
But in some less obvious cases, we can't detect the issue at compile-time, so
85
- prelude. ts will reject the code at runtime; for instance if you call
85
+ prelude- ts will reject the code at runtime; for instance if you call
86
86
` HashSet.of(Vector.of([1])) ` you'll get an exception at runtime:
87
87
88
88
Error building a HashSet: element doesn't support true equality: Vector([1])
@@ -92,7 +92,7 @@ prelude.ts will reject the code at runtime; for instance if you call
92
92
## Installation
93
93
94
94
Typescript must know about ` Iterable ` , an ES6 feature (but present in most browsers)
95
- to compile prelude. ts. If you use typescript and target ES5, a minimum change to your tsconfig.json
95
+ to compile prelude- ts. If you use typescript and target ES5, a minimum change to your tsconfig.json
96
96
could be to add:
97
97
98
98
``` json
@@ -104,9 +104,9 @@ could be to add:
104
104
### Using in nodejs
105
105
106
106
Just add the dependency in your ` package.json ` and start using it (like
107
- ` import { Vector } from "prelude. ts"; ` , or ` const { Vector } = require("prelude. ts"); `
107
+ ` import { Vector } from "prelude- ts"; ` , or ` const { Vector } = require("prelude- ts"); `
108
108
if you use commonjs).
109
- Everything should work, including type-checking if you use typescript. Prelude. ts also provides
109
+ Everything should work, including type-checking if you use typescript. prelude- ts also provides
110
110
pretty-printing in the node REPL.
111
111
112
112
### Using in the browser
@@ -122,13 +122,13 @@ include the relevant one in your index.html in script tags:
122
122
<script src =" node_modules/prelude.ts/dist/src/prelude_ts.min.js" ></script >
123
123
```
124
124
125
- You shouldn't have an issue to import prelude. ts in your application, but if you use
125
+ You shouldn't have an issue to import prelude- ts in your application, but if you use
126
126
modules it gets a little more complicated; One solution if you use them is to create
127
127
an ` imports.d.ts ` file with the following contents:
128
128
129
129
``` typescript
130
130
// https://github.com/Microsoft/TypeScript/issues/3180#issuecomment-283007750
131
- import * as _P from ' prelude. ts' ;
131
+ import * as _P from ' prelude- ts' ;
132
132
export as namespace prelude_ts ;
133
133
export = _P ;
134
134
```
@@ -144,15 +144,15 @@ To get the values without namespace.
144
144
Finally, if you also include ` dist/src/chrome_dev_tools_formatters.js ` through
145
145
a ` script ` tag, and [ enable Chrome custom formatters] ( http://bit.ly/object-formatters ) ,
146
146
then you can get
147
- [ a nice display of prelude. ts values in the chrome debugger] ( https://raw.githubusercontent.com/wiki/emmanueltouzery/prelude.ts/chrome_formatters.png ) .
147
+ [ a nice display of prelude- ts values in the chrome debugger] ( https://raw.githubusercontent.com/wiki/emmanueltouzery/prelude.ts/chrome_formatters.png ) .
148
148
149
149
## Wishlist/upcoming features
150
150
151
151
* CharSeq, a string wrapper?
152
152
* Non-empty vector? (already have [ non-empty linkedlist] ( http://emmanueltouzery.github.io/prelude.ts/latest/apidoc/classes/linkedlist.conslinkedlist.html ) )
153
153
* More functions on existing classes
154
154
155
- ## Out of scope for prelude. ts
155
+ ## Out of scope for prelude- ts
156
156
157
157
* Free monads
158
158
* Monad transformers
@@ -166,16 +166,16 @@ such as typescript.
166
166
167
167
* [ monet.js] ( https://monet.github.io/monet.js/ ) -- only has the ` List ` and
168
168
` Option ` collections, implemented in functional-style ES5. The implementation,
169
- using recursion, means its list type is noticeably slower than prelude. ts's.
169
+ using recursion, means its list type is noticeably slower than prelude- ts's.
170
170
* [ immutables.js] ( https://facebook.github.io/immutable-js/ ) -- doesn't have the
171
171
` Option ` concept, the types can be clunky.
172
172
* [ sanctuary] ( https://github.com/sanctuary-js/sanctuary )
173
- offers global functions like ` S.filter(S.where(...)) ` while prelude. ts prefers a
173
+ offers global functions like ` S.filter(S.where(...)) ` while prelude- ts prefers a
174
174
fluent-api style like ` list.filter(..).sortBy(...) ` . Also, sanctuary doesn't
175
175
offer sets and maps. On the other hand, sanctuary has some JS runtime type system
176
- which prelude. ts doesn't have.
176
+ which prelude- ts doesn't have.
177
177
* [ ramdajs] ( http://ramdajs.com/ ) offers global functions like
178
- ` R.filter(R.where(...)) ` while prelude. ts prefers a
178
+ ` R.filter(R.where(...)) ` while prelude- ts prefers a
179
179
fluent-api style like ` list.filter(..).sortBy(...) ` . Also, ramda doesn't offer
180
180
sets and maps. Ramda also uses currying a lot out of the box, which may not
181
181
be intuitive to a number of developers. In prelude,
@@ -184,8 +184,8 @@ such as typescript.
184
184
are opt-in.
185
185
* [ lodash] ( https://lodash.com ) also has the global functions, and many functions
186
186
mutate the collections.
187
- * [ vavr] ( http://www.vavr.io/ ) -- it's a java library, but it's the main inspiration for prelude. ts.
188
- Note that vavr is inspired by the scala library, so prelude. ts also is,
187
+ * [ vavr] ( http://www.vavr.io/ ) -- it's a java library, but it's the main inspiration for prelude- ts.
188
+ Note that vavr is inspired by the scala library, so prelude- ts also is,
189
189
transitively.
190
190
191
191
## Typescript version
@@ -206,7 +206,7 @@ requires typescript 3.0 or newer.
206
206
npm run benchmarks
207
207
208
208
[ npm-image ] : https://img.shields.io/npm/v/prelude.ts.svg?style=flat-square
209
- [ npm-url ] : https://www.npmjs.com/package/prelude. ts
209
+ [ npm-url ] : https://www.npmjs.com/package/prelude- ts
210
210
[ circleci-image ] : https://circleci.com/gh/emmanueltouzery/prelude.ts.svg?style=shield&circle-token=6d8b74ef7ea7d1c204e77c4f88b05348682b4161
211
211
[ circleci-url ] : https://circleci.com/gh/emmanueltouzery/prelude.ts
212
212
[ apidoc-image ] : http://emmanueltouzery.github.io/prelude.ts/apidoc.svg
0 commit comments