-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Maybe): add tryLast, bump to beta.4
- Loading branch information
1 parent
e0bf5ff
commit 56abbf0
Showing
3 changed files
with
73 additions
and
1 deletion.
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
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,36 @@ | ||
import { Maybe } from '@/src/maybe'; | ||
describe('Maybe', () => { | ||
describe('tryLast', () => { | ||
test('creates a Maybe with a value when the array has a value', () => { | ||
const items = [1, 2, 3]; | ||
|
||
const sut = Maybe.tryLast(items); | ||
|
||
expect(sut).toHaveValue(items[2]); | ||
}); | ||
|
||
test('creates a Maybe with no value when the array is empty', () => { | ||
const items: number[] = []; | ||
|
||
const sut = Maybe.tryLast(items); | ||
|
||
expect(sut).toHaveNoValue(); | ||
}); | ||
|
||
test('creates a Maybe with the last value which matches the predicate', () => { | ||
const items = [1, 2, 3, 4]; | ||
|
||
const sut = Maybe.tryLast(items, (i) => i > 2); | ||
|
||
expect(sut).toHaveValue(4); | ||
}); | ||
|
||
test('creates a Maybe with no value when the predicate has no matches', () => { | ||
const items = [1, 2, 3, 4]; | ||
|
||
const sut = Maybe.tryLast(items, (i) => i > 10); | ||
|
||
expect(sut).toHaveNoValue(); | ||
}); | ||
}); | ||
}); |