-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93e237e
commit 4f0190d
Showing
19 changed files
with
1,061 additions
and
121 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export function toIterable<T, TF extends () => IterableIterator<T>>(f: TF) { | ||
return { | ||
[Symbol.iterator]: f, | ||
toJSON:function () { | ||
toJSON(): T[] { | ||
return [...f()] | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
import { every, _every } from './every' | ||
|
||
/** | ||
* returns `true` if *all* elements in `src` return `true` when passed to `pred` | ||
* @remarks | ||
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _every} | ||
* @alias of {@link every} | ||
* @param src source sequence | ||
* @param pred indexed predicate function | ||
*/ | ||
export const all = every | ||
/** | ||
* returns `true` if *all* elements in `src` return `true` when passed to `pred` | ||
* @alias of {@link _every} | ||
* @param src source sequence | ||
* @param pred indexed predicate function | ||
*/ | ||
export const _all = _every |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import { deferP0 } from 'ts-functional-pipe' | ||
import { toIterable } from '../helpers/toIterable' | ||
|
||
/** | ||
* append a single item to the end of a sequence | ||
* @param src source sequence | ||
* @param item the item to append | ||
*/ | ||
export function _append<T>(src: Iterable<T>, item: T): Iterable<T> { | ||
return toIterable(function*() { | ||
return toIterable(function* () { | ||
for (const x of src) { | ||
yield x | ||
} | ||
yield item | ||
}) | ||
} | ||
|
||
/** | ||
* append a single item to the end of a sequence | ||
* @remarks | ||
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _append} | ||
* @param src source sequence | ||
* @param item the item to append | ||
*/ | ||
export const append = deferP0(_append) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
import { toIterable } from '../helpers/toIterable' | ||
import { IndexedPredicate } from '../types/IndexedPredicate' | ||
import { deferP0 } from 'ts-functional-pipe' | ||
import { _indexed } from './indexed' | ||
|
||
/** | ||
* creates a new sequence with every item of the source sequence for which the predicate function returns `true` | ||
* @param src source sequence | ||
* @param pred a function that returns `true` to signal inclusion, `false` to exclude | ||
* @returns a new (possibly shorter) sequence with some items filtered away | ||
*/ | ||
export function _filter<T>(src: Iterable<T>, pred: IndexedPredicate<T>): Iterable<T> { | ||
return toIterable(function* () { | ||
let i = 0 | ||
for (const x of src) { | ||
if (pred(x, i++)) { | ||
yield x | ||
const s = _indexed(src) | ||
for (const x of s) { | ||
if (pred(...x)) { | ||
yield x[0] | ||
} | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* creates a new sequence with every item of the source sequence for which the predicate function returns `true` | ||
* | ||
* @remarks | ||
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _filter} | ||
* | ||
* @param src source sequence | ||
* @param pred a function that returns `true` to signal inclusion, `false` to exclude | ||
* @returns a new (possibly shorter) sequence with some items filtered away | ||
*/ | ||
export const filter = deferP0(_filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
import { map, _map } from './map' | ||
|
||
/** | ||
* Creates a new sequence populated with the results of calling a provided function on every element in the source sequence | ||
* @remarks | ||
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _map} | ||
* @alias of {@link map} | ||
* @param src source sequence | ||
* @param selector function to transform each item `T` in the source sequence into `TOut` | ||
* @returns A new sequence with each element being the result of the selector function. | ||
*/ | ||
|
||
export const select = map | ||
/** | ||
* Creates a new sequence populated with the results of calling a provided function on every element in the source sequence | ||
* @alias of {@link _map} | ||
* @param src source sequence | ||
* @param selector function to transform each item `T` in the source sequence into `TOut` | ||
* @returns A new sequence with each element being the result of the selector function. | ||
*/ | ||
export const _select = _map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
import { filter, _filter } from './filter' | ||
|
||
/** | ||
* creates a new sequence with every item of the source sequence for which the predicate function returns `true` | ||
* @remarks | ||
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _filter} | ||
* @alias of {@link filter} | ||
* | ||
* @param src source sequence | ||
* @param pred a function that returns `true` to signal inclusion, `false` to exclude | ||
* @returns a new (possibly shorter) sequence with some items filtered away | ||
*/ | ||
|
||
export const where = filter | ||
/** | ||
* creates a new sequence with every item of the source sequence for which the predicate function returns `true` | ||
* | ||
* @alias of {@link _filter} | ||
* @param src source sequence | ||
* @param pred a function that returns `true` to signal inclusion, `false` to exclude | ||
* @returns a new (possibly shorter) sequence with some items filtered away | ||
*/ | ||
export const _where = _filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface GroupedIterable<K, V> extends Iterable<V> { | ||
key: K; | ||
toJSON(): Array<V>; | ||
key: K | ||
toJSON(): V[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
/** | ||
* Defines a predicate that takes a value `x:T` and number that represents the position of `x` in whichever sequence | ||
* it is applied to and returns `true` or `false` usually to signal inclusion in an output list | ||
* @example {@link _filter} | ||
*/ | ||
|
||
export type IndexedPredicate<T> = (x: T, i: number) => Boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
/** | ||
* Defines a selector that takes a value `x:T` and number that represents the position of `x` in whichever sequence it is applied to and transforms that `T` into a `TOut` | ||
* @example {@link _map} | ||
*/ | ||
export type IndexedSelector<T, TOut> = (x: T, i: number) => TOut |