Skip to content

Commit 2b47de5

Browse files
committed
Remove runkit
1 parent 21de701 commit 2b47de5

File tree

14 files changed

+33
-1468
lines changed

14 files changed

+33
-1468
lines changed

README.md

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ bun add immutable
7373

7474
Then require it into any module.
7575

76-
<!-- runkit:activate -->
77-
7876
```js
7977
const { Map } = require('immutable');
8078
const map1 = Map({ a: 1, b: 2, c: 3 });
@@ -136,8 +134,6 @@ lib. Include either `"target": "es2015"` or `"lib": "es2015"` in your
136134
`tsconfig.json`, or provide `--target es2015` or `--lib es2015` to the
137135
`tsc` command.
138136

139-
<!-- runkit:activate -->
140-
141137
```js
142138
const { Map } = require('immutable');
143139
const map1 = Map({ a: 1, b: 2, c: 3 });
@@ -187,8 +183,6 @@ treat Immutable.js collections as values, it's important to use the
187183
`Immutable.is()` function or `.equals()` method to determine _value equality_
188184
instead of the `===` operator which determines object _reference identity_.
189185

190-
<!-- runkit:activate -->
191-
192186
```js
193187
const { Map } = require('immutable');
194188
const map1 = Map({ a: 1, b: 2, c: 3 });
@@ -205,8 +199,6 @@ which would prefer to re-run the function if a deeper equality check could
205199
potentially be more costly. The `===` equality check is also used internally by
206200
`Immutable.is` and `.equals()` as a performance optimization.
207201

208-
<!-- runkit:activate -->
209-
210202
```js
211203
const { Map } = require('immutable');
212204
const map1 = Map({ a: 1, b: 2, c: 3 });
@@ -219,8 +211,6 @@ to it instead of copying the entire object. Because a reference is much smaller
219211
than the object itself, this results in memory savings and a potential boost in
220212
execution speed for programs which rely on copies (such as an undo-stack).
221213

222-
<!-- runkit:activate -->
223-
224214
```js
225215
const { Map } = require('immutable');
226216
const map = Map({ a: 1, b: 2, c: 3 });
@@ -230,7 +220,6 @@ const mapCopy = map; // Look, "copies" are free!
230220
[React]: https://reactjs.org/
231221
[Flux]: https://facebook.github.io/flux/docs/in-depth-overview/
232222

233-
234223
## JavaScript-first API
235224

236225
While Immutable.js is inspired by Clojure, Scala, Haskell and other functional
@@ -248,8 +237,6 @@ the collection, like `push`, `set`, `unshift` or `splice`, instead return a new
248237
immutable collection. Methods which return new arrays, like `slice` or `concat`,
249238
instead return new immutable collections.
250239

251-
<!-- runkit:activate -->
252-
253240
```js
254241
const { List } = require('immutable');
255242
const list1 = List([1, 2]);
@@ -268,8 +255,6 @@ Almost all of the methods on [Array][] will be found in similar form on
268255
found on `Immutable.Set`, including collection operations like `forEach()`
269256
and `map()`.
270257

271-
<!-- runkit:activate -->
272-
273258
```js
274259
const { Map } = require('immutable');
275260
const alpha = Map({ a: 1, b: 2, c: 3, d: 4 });
@@ -283,8 +268,6 @@ Designed to inter-operate with your existing JavaScript, Immutable.js
283268
accepts plain JavaScript Arrays and Objects anywhere a method expects a
284269
`Collection`.
285270

286-
<!-- runkit:activate -->
287-
288271
```js
289272
const { Map, List } = require('immutable');
290273
const map1 = Map({ a: 1, b: 2, c: 3, d: 4 });
@@ -305,13 +288,11 @@ collection methods on JavaScript Objects, which otherwise have a very sparse
305288
native API. Because Seq evaluates lazily and does not cache intermediate
306289
results, these operations can be extremely efficient.
307290

308-
<!-- runkit:activate -->
309-
310291
```js
311292
const { Seq } = require('immutable');
312293
const myObject = { a: 1, b: 2, c: 3 };
313294
Seq(myObject)
314-
.map(x => x * x)
295+
.map((x) => x * x)
315296
.toObject();
316297
// { a: 1, b: 4, c: 9 }
317298
```
@@ -320,8 +301,6 @@ Keep in mind, when using JS objects to construct Immutable Maps, that
320301
JavaScript Object properties are always strings, even if written in a quote-less
321302
shorthand, while Immutable Maps accept keys of any type.
322303

323-
<!-- runkit:activate -->
324-
325304
```js
326305
const { fromJS } = require('immutable');
327306

@@ -345,8 +324,6 @@ All Immutable Collections also implement `toJSON()` allowing them to be passed
345324
to `JSON.stringify` directly. They also respect the custom `toJSON()` methods of
346325
nested objects.
347326

348-
<!-- runkit:activate -->
349-
350327
```js
351328
const { Map, List } = require('immutable');
352329
const deep = Map({ a: 1, b: 2, c: List([3, 4, 5]) });
@@ -369,7 +346,7 @@ browsers, they need to be translated to ES5.
369346

370347
```js
371348
// ES2015
372-
const mapped = foo.map(x => x * x);
349+
const mapped = foo.map((x) => x * x);
373350
// ES5
374351
var mapped = foo.map(function (x) {
375352
return x * x;
@@ -379,8 +356,6 @@ var mapped = foo.map(function (x) {
379356
All Immutable.js collections are [Iterable][iterators], which allows them to be
380357
used anywhere an Iterable is expected, such as when spreading into an Array.
381358

382-
<!-- runkit:activate -->
383-
384359
```js
385360
const { List } = require('immutable');
386361
const aList = List([1, 2, 3]);
@@ -395,14 +370,11 @@ not always be well defined, as is the case for the `Map` and `Set`.
395370
[Classes]: https://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes
396371
[Modules]: https://www.2ality.com/2014/09/es6-modules-final.html
397372

398-
399373
## Nested Structures
400374

401375
The collections in Immutable.js are intended to be nested, allowing for deep
402376
trees of data, similar to JSON.
403377

404-
<!-- runkit:activate -->
405-
406378
```js
407379
const { fromJS } = require('immutable');
408380
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });
@@ -413,8 +385,6 @@ A few power-tools allow for reading and operating on nested data. The
413385
most useful are `mergeDeep`, `getIn`, `setIn`, and `updateIn`, found on `List`,
414386
`Map` and `OrderedMap`.
415387

416-
<!-- runkit:activate -->
417-
418388
```js
419389
const { fromJS } = require('immutable');
420390
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });
@@ -424,11 +394,11 @@ const nested2 = nested.mergeDeep({ a: { b: { d: 6 } } });
424394

425395
console.log(nested2.getIn(['a', 'b', 'd'])); // 6
426396

427-
const nested3 = nested2.updateIn(['a', 'b', 'd'], value => value + 1);
397+
const nested3 = nested2.updateIn(['a', 'b', 'd'], (value) => value + 1);
428398
console.log(nested3);
429399
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ], d: 7 } } }
430400

431-
const nested4 = nested3.updateIn(['a', 'b', 'c'], list => list.push(6));
401+
const nested4 = nested3.updateIn(['a', 'b', 'c'], (list) => list.push(6));
432402
// Map { a: Map { b: Map { c: List [ 3, 4, 5, 6 ], d: 7 } } }
433403
```
434404

@@ -443,8 +413,6 @@ determines if two variables represent references to the same object instance.
443413
Consider the example below where two identical `Map` instances are not
444414
_reference equal_ but are _value equal_.
445415

446-
<!-- runkit:activate -->
447-
448416
```js
449417
// First consider:
450418
const obj1 = { a: 1, b: 2, c: 3 };
@@ -462,8 +430,6 @@ is(map1, map2); // alternatively can use the is() function
462430
Value equality allows Immutable.js collections to be used as keys in Maps or
463431
values in Sets, and retrieved with different but equivalent collections:
464432

465-
<!-- runkit:activate -->
466-
467433
```js
468434
const { Map, Set } = require('immutable');
469435
const map1 = Map({ a: 1, b: 2, c: 3 });
@@ -502,8 +468,6 @@ When possible, Immutable.js avoids creating new objects for updates where no
502468
change in _value_ occurred, to allow for efficient _reference equality_ checking
503469
to quickly determine if no change occurred.
504470

505-
<!-- runkit:activate -->
506-
507471
```js
508472
const { Map } = require('immutable');
509473
const originalMap = Map({ a: 1, b: 2, c: 3 });
@@ -515,8 +479,6 @@ However updates which do result in a change will return a new reference. Each
515479
of these operations occur independently, so two similar updates will not return
516480
the same reference:
517481

518-
<!-- runkit:activate -->
519-
520482
```js
521483
const { Map } = require('immutable');
522484
const originalMap = Map({ a: 1, b: 2, c: 3 });
@@ -549,8 +511,6 @@ exactly how Immutable.js applies complex mutations itself.
549511
As an example, building `list2` results in the creation of 1, not 3, new
550512
immutable Lists.
551513

552-
<!-- runkit:activate -->
553-
554514
```js
555515
const { List } = require('immutable');
556516
const list1 = List([1, 2, 3]);
@@ -592,8 +552,8 @@ For example, the following performs no work, because the resulting
592552
```js
593553
const { Seq } = require('immutable');
594554
const oddSquares = Seq([1, 2, 3, 4, 5, 6, 7, 8])
595-
.filter(x => x % 2 !== 0)
596-
.map(x => x * x);
555+
.filter((x) => x % 2 !== 0)
556+
.map((x) => x * x);
597557
```
598558

599559
Once the `Seq` is used, it performs only the work necessary. In this
@@ -606,8 +566,6 @@ oddSquares.get(1); // 9
606566

607567
Any collection can be converted to a lazy Seq with `Seq()`.
608568

609-
<!-- runkit:activate -->
610-
611569
```js
612570
const { Map, Seq } = require('immutable');
613571
const map = Map({ a: 1, b: 2, c: 3 });
@@ -620,22 +578,20 @@ expression of logic that can otherwise be very tedious:
620578
```js
621579
lazySeq
622580
.flip()
623-
.map(key => key.toUpperCase())
581+
.map((key) => key.toUpperCase())
624582
.flip();
625583
// Seq { A: 1, B: 2, C: 3 }
626584
```
627585

628586
As well as expressing logic that would otherwise seem memory or time
629587
limited, for example `Range` is a special kind of Lazy sequence.
630588

631-
<!-- runkit:activate -->
632-
633589
```js
634590
const { Range } = require('immutable');
635591
Range(1, Infinity)
636592
.skip(1000)
637-
.map(n => -n)
638-
.filter(n => n % 2 === 0)
593+
.map((n) => -n)
594+
.filter((n) => n % 2 === 0)
639595
.take(2)
640596
.reduce((r, n) => r * n, 1);
641597
// 1006008
@@ -646,8 +602,8 @@ Range(1, Infinity)
646602
The `filter()`, `groupBy()`, and `partition()` methods are similar in that they
647603
all divide a collection into parts based on applying a function to each element.
648604
All three call the predicate or grouping function once for each item in the
649-
input collection. All three return zero or more collections of the same type as
650-
their input. The returned collections are always distinct from the input
605+
input collection. All three return zero or more collections of the same type as
606+
their input. The returned collections are always distinct from the input
651607
(according to `===`), even if the contents are identical.
652608

653609
Of these methods, `filter()` is the only one that is lazy and the only one which
@@ -658,21 +614,21 @@ methods to form a pipeline of operations.
658614
The `partition()` method is similar to an eager version of `filter()`, but it
659615
returns two collections; the first contains the items that would have been
660616
discarded by `filter()`, and the second contains the items that would have been
661-
kept. It always returns an array of exactly two collections, which can make it
662-
easier to use than `groupBy()`. Compared to making two separate calls to
617+
kept. It always returns an array of exactly two collections, which can make it
618+
easier to use than `groupBy()`. Compared to making two separate calls to
663619
`filter()`, `partition()` makes half as many calls it the predicate passed to
664620
it.
665621

666622
The `groupBy()` method is a more generalized version of `partition()` that can
667-
group by an arbitrary function rather than just a predicate. It returns a map
623+
group by an arbitrary function rather than just a predicate. It returns a map
668624
with zero or more entries, where the keys are the values returned by the
669625
grouping function, and the values are nonempty collections of the corresponding
670-
arguments. Although `groupBy()` is more powerful than `partition()`, it can be
626+
arguments. Although `groupBy()` is more powerful than `partition()`, it can be
671627
harder to use because it is not always possible predict in advance how many
672628
entries the returned map will have and what their keys will be.
673629

674630
| Summary | `filter` | `partition` | `groupBy` |
675-
|:------------------------------|:---------|:------------|:---------------|
631+
| :---------------------------- | :------- | :---------- | :------------- |
676632
| ease of use | easiest | moderate | hardest |
677633
| generality | least | moderate | most |
678634
| laziness | lazy | eager | eager |
@@ -684,49 +640,63 @@ entries the returned map will have and what their keys will be.
684640
## Additional Tools and Resources
685641

686642
- [Atom-store](https://github.com/jameshopkins/atom-store/)
643+
687644
- A Clojure-inspired atom implementation in Javascript with configurability
688645
for external persistance.
689646

690647
- [Chai Immutable](https://github.com/astorije/chai-immutable)
648+
691649
- If you are using the [Chai Assertion Library](https://chaijs.com/), this
692650
provides a set of assertions to use against Immutable.js collections.
693651

694652
- [Fantasy-land](https://github.com/fantasyland/fantasy-land)
653+
695654
- Specification for interoperability of common algebraic structures in JavaScript.
696655

697656
- [Immutagen](https://github.com/pelotom/immutagen)
657+
698658
- A library for simulating immutable generators in JavaScript.
699659

700660
- [Immutable-cursor](https://github.com/redbadger/immutable-cursor)
661+
701662
- Immutable cursors incorporating the Immutable.js interface over
702-
Clojure-inspired atom.
663+
Clojure-inspired atom.
703664

704665
- [Immutable-ext](https://github.com/DrBoolean/immutable-ext)
666+
705667
- Fantasyland extensions for immutablejs
706668

707669
- [Immutable-js-tools](https://github.com/madeinfree/immutable-js-tools)
670+
708671
- Util tools for immutable.js
709672

710673
- [Immutable-Redux](https://github.com/gajus/redux-immutable)
674+
711675
- redux-immutable is used to create an equivalent function of Redux
712-
combineReducers that works with Immutable.js state.
676+
combineReducers that works with Immutable.js state.
713677

714678
- [Immutable-Treeutils](https://github.com/lukasbuenger/immutable-treeutils)
679+
715680
- Functional tree traversal helpers for ImmutableJS data structures.
716681

717682
- [Irecord](https://github.com/ericelliott/irecord)
683+
718684
- An immutable store that exposes an RxJS observable. Great for React.
719685

720686
- [Mudash](https://github.com/brianneisler/mudash)
687+
721688
- Lodash wrapper providing Immutable.JS support.
722689

723690
- [React-Immutable-PropTypes](https://github.com/HurricaneJames/react-immutable-proptypes)
691+
724692
- PropType validators that work with Immutable.js.
725693

726694
- [Redux-Immutablejs](https://github.com/indexiatech/redux-immutablejs)
695+
727696
- Redux Immutable facilities.
728697

729698
- [Rxstate](https://github.com/yamalight/rxstate)
699+
730700
- Simple opinionated state management library based on RxJS and Immutable.js.
731701

732702
- [Transit-Immutable-js](https://github.com/glenjamin/transit-immutable-js)

src/functional/get.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ import { has } from './has';
88
*
99
* A functional alternative to `collection.get(key)` which will also work on
1010
* plain Objects and Arrays as an alternative for `collection[key]`.
11-
*
12-
* <!-- runkit:activate -->
13-
* ```js
14-
* import { get } from 'immutable';
15-
*
16-
* get([ 'dog', 'frog', 'cat' ], 1) // 'frog'
17-
* get({ x: 123, y: 456 }, 'x') // 123
18-
* get({ x: 123, y: 456 }, 'z', 'ifNotSet') // 'ifNotSet'
19-
* ```
2011
*/
2112
export function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
2213
export function get<K, V, NSV>(

src/functional/getIn.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ type Key = GetTypeParameters[1];
1414
*
1515
* A functional alternative to `collection.getIn(keypath)` which will also
1616
* work with plain Objects and Arrays.
17-
*
18-
* <!-- runkit:activate -->
19-
* ```js
20-
* import { getIn } from 'immutable';
21-
*
22-
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
23-
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
24-
* ```
2517
*/
2618
export function getIn(
2719
collection: CollectionType,

0 commit comments

Comments
 (0)