-
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.
Merge pull request #11 from ilteoood/feat/defaultTo
feat: defaultTo
- Loading branch information
Showing
11 changed files
with
154 additions
and
56 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { map } from "./map"; | ||
|
||
export const defaultTo = <T>( | ||
defaultValue: T, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
) => { | ||
return map( | ||
(chunk) => chunk ?? defaultValue, | ||
writableStrategy, | ||
readableStrategy, | ||
); | ||
}; |
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,9 +1,13 @@ | ||
import { filter } from "../filter"; | ||
|
||
export const greaterThan = ( | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
) => { | ||
return filter((chunk: number) => chunk > value, writableStrategy, readableStrategy); | ||
return filter( | ||
(chunk: number) => chunk > value, | ||
writableStrategy, | ||
readableStrategy, | ||
); | ||
}; |
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,9 +1,13 @@ | ||
import { filter } from "../filter"; | ||
|
||
export const greaterThanEqual = ( | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
) => { | ||
return filter((chunk: number) => chunk >= value, writableStrategy, readableStrategy); | ||
return filter( | ||
(chunk: number) => chunk >= value, | ||
writableStrategy, | ||
readableStrategy, | ||
); | ||
}; |
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,9 +1,13 @@ | ||
import { filter } from "../filter"; | ||
|
||
export const lessThan = ( | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
) => { | ||
return filter((chunk: number) => chunk < value, writableStrategy, readableStrategy); | ||
return filter( | ||
(chunk: number) => chunk < value, | ||
writableStrategy, | ||
readableStrategy, | ||
); | ||
}; |
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,9 +1,13 @@ | ||
import { filter } from "../filter"; | ||
|
||
export const lessThanEqual = ( | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
value: number, | ||
writableStrategy?: QueuingStrategy, | ||
readableStrategy?: QueuingStrategy, | ||
) => { | ||
return filter((chunk: number) => chunk <= value, writableStrategy, readableStrategy); | ||
return filter( | ||
(chunk: number) => chunk <= value, | ||
writableStrategy, | ||
readableStrategy, | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { defaultTo } from "../src/defaultTo"; | ||
import { fromIterable } from "../src/fromIterable"; | ||
import { pipeline } from "../src/pipeline"; | ||
import { toArray } from "../src/toArray"; | ||
|
||
describe("defaultTo", () => { | ||
it("should work with empty stream", async () => { | ||
const destinationArray = []; | ||
|
||
await pipeline(fromIterable([]), defaultTo(1), toArray(destinationArray)); | ||
|
||
expect(destinationArray).toEqual([]); | ||
}); | ||
|
||
it("should work with falsy values", async () => { | ||
const destinationArray = []; | ||
|
||
await pipeline( | ||
fromIterable([false, 0]), | ||
defaultTo(1), | ||
toArray(destinationArray), | ||
); | ||
|
||
expect(destinationArray).toEqual([false, 0]); | ||
}); | ||
|
||
it("should work with nullish values", async () => { | ||
const destinationArray = []; | ||
|
||
await pipeline( | ||
fromIterable([null, undefined]), | ||
defaultTo(1), | ||
toArray(destinationArray), | ||
); | ||
|
||
expect(destinationArray).toEqual([1, 1]); | ||
}); | ||
}); |
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