Skip to content

Commit

Permalink
Add partition to flow spec (#1920)
Browse files Browse the repository at this point in the history
Co-authored-by: Dagur Ammendrup <dagurp@vivaldi.com>
  • Loading branch information
Dagur and Dagur Ammendrup committed Jan 2, 2023
1 parent 7e33ca9 commit 03d8b39
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions type-definitions/flow-tests/immutable-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var numberOrStringStack: Stack<string | number> = Stack();
var number: number = 0;
var stringToNumberCollection: KeyedCollection<string, number> = stringToNumber;
var numberToStringCollection: KeyedCollection<number, string> = numberToString;
var partitions: [List<number>, List<number>];

numberList = List([1, 2]);
var numberListSize: number = numberList.size;
Expand Down Expand Up @@ -269,6 +270,8 @@ numberList = List.of(1).flatten();
// Specific type for filter(Boolean) which removes nullability.
numberList = nullableNumberList.filter(Boolean);

partitions = List([1,2,3]).partition(value => value % 2);

/* Map */

stringToNumber = Map();
Expand Down Expand Up @@ -484,6 +487,8 @@ stringToNumber = stringToNullableNumber;
// Specific type for filter(Boolean) which removes nullability.
stringToNumber = stringToNullableNumber.filter(Boolean);

[anyMap, ] = Map({ "a": 1, "b": 2}).partition((key, index, iter) => key % 2)

/* OrderedMap */

orderedStringToNumber = Map({ a: 1 }).toOrderedMap();
Expand Down
55 changes: 55 additions & 0 deletions type-definitions/immutable.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ declare class KeyedCollection<K, +V> extends Collection<K, V> {
context?: mixed
): KeyedCollection<K, V>;

partition(
predicate: (value: V, key: K, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -484,6 +489,11 @@ declare class IndexedCollection<+T> extends Collection<number, T> {
context?: mixed
): IndexedCollection<T>;

partition(
predicate: (value: T, index: number, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, index: number, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -519,6 +529,11 @@ declare class SetCollection<+T> extends Collection<T, T> {
context?: mixed
): SetCollection<T>;

partition(
predicate: (value: T, value: T, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, value: T, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -570,6 +585,11 @@ declare class KeyedSeq<K, +V> extends Seq<K, V> mixins KeyedCollection<K, V> {
context?: mixed
): KeyedSeq<K, V>;

partition(
predicate: (value: V, key: K, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -612,6 +632,11 @@ declare class IndexedSeq<+T>
context?: mixed
): IndexedSeq<T>;

partition(
predicate: (value: T, index: number, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, index: number, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -729,6 +754,11 @@ declare class SetSeq<+T> extends Seq<T, T> mixins SetCollection<T> {
context?: mixed
): SetSeq<T>;

partition(
predicate: (value: T, value: T, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, value: T, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -949,6 +979,11 @@ declare class List<+T>
context?: mixed
): List<T>;

partition(
predicate: (value: T, index: number, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, index: number, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -1124,6 +1159,11 @@ declare class Map<K, +V>
context?: mixed
): Map<K, V>;

partition(
predicate: (value: V, key: K, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -1221,6 +1261,11 @@ declare class OrderedMap<K, +V>
context?: mixed
): OrderedMap<K, V>;

partition(
predicate: (value: V, key: K, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -1285,6 +1330,11 @@ declare class Set<+T> extends SetCollection<T> {
context?: mixed
): Set<T>;

partition(
predicate: (value: T, value: T, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, value: T, iter: this) => M,
context?: mixed
Expand Down Expand Up @@ -1327,6 +1377,11 @@ declare class OrderedSet<+T> extends Set<T> {
context?: mixed
): OrderedSet<T>;

partition(
predicate: (value: T, value: T, iter: this) => mixed,
context?: mixed
): [this, this];

map<M>(
mapper: (value: T, value: T, iter: this) => M,
context?: mixed
Expand Down

0 comments on commit 03d8b39

Please sign in to comment.