Skip to content

Commit bf9e148

Browse files
authored
Merge pull request #6 from seangwright/feat/pipeable-operators
2 parents ff85358 + 4baa057 commit bf9e148

14 files changed

Lines changed: 1826 additions & 1393 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,36 @@ const maybe = Maybe.none<Food>()
136136
}); // None!
137137
```
138138

139+
#### Pipe
140+
141+
```typescript
142+
// custom-operators.ts
143+
import { logger, LogLevel } from 'logger';
144+
145+
export function log<TValue>(
146+
messageCreator: FunctionOfTtoK<TValue, string>,
147+
logLevel: LogLevel = 'debug'
148+
): MaybeOpFn<TValue, TValue> {
149+
return (maybe) => {
150+
if (maybe.hasValue) {
151+
logger.log(messageCreator(maybe.getValueOrThrow()), logLevel);
152+
} else {
153+
logger.error('No value found!');
154+
}
155+
156+
return maybe;
157+
};
158+
}
159+
160+
// app.ts
161+
import { log } from './custom-operators.ts';
162+
163+
const maybe = Maybe.some('apple')
164+
.pipe(log((f) => `My fruit is ${f}`, 'information'))
165+
.map((f) => `${f} and banana`)
166+
.pipe(log((f) => `Now I have ${f}`));
167+
```
168+
139169
### MaybeAsync
140170

141171
`MaybeAsync` represents a future value (`Promise`) that might or might not exist.

jest.config.js renamed to jest.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2-
export default {
1+
import { InitialOptionsTsJest } from 'ts-jest';
2+
3+
const config: InitialOptionsTsJest = {
34
preset: 'ts-jest',
45
testEnvironment: 'node',
56
globals: {
@@ -14,3 +15,5 @@ export default {
1415
setupFilesAfterEnv: ['./test/expectExtensions.ts'],
1516
extensionsToTreatAsEsm: ['.ts'],
1617
};
18+
19+
export default config;

0 commit comments

Comments
 (0)