-
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
b1c757e
commit e9b014e
Showing
4 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import prop from '../../modules/prop' | ||
|
||
describe('prop', () => { | ||
test('returns the value at the given key', () => { | ||
const key = 'name' | ||
const obj = { name: 'Tim' } | ||
const result = prop(key, obj) | ||
|
||
expect(result).toBe('Tim') | ||
}) | ||
|
||
test('is curried', () => { | ||
const key = 'name' | ||
const obj = { name: 'Tim' } | ||
const result = prop(key)(obj) | ||
|
||
expect(result).toBe('Tim') | ||
}) | ||
}) |
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,29 @@ | ||
import propOr from '../../modules/propOr' | ||
|
||
describe('propOr', () => { | ||
test('returns the value at the given key', () => { | ||
const key = 'name' | ||
const obj = { name: 'Tim' } | ||
const result = propOr('', key, obj) | ||
|
||
expect(result).toBe('Tim') | ||
}) | ||
|
||
test('returns the default if key is undefined', () => { | ||
const key = 'age' | ||
const obj = { name: 'Tim' } | ||
const def = 18 | ||
const result = propOr(def, key, obj) | ||
|
||
expect(result).toBe(def) | ||
}) | ||
|
||
test('is a curried function', () => { | ||
const key = 'age' | ||
const obj = { name: 'Tim' } | ||
const def = 18 | ||
const result = propOr(def)(key)(obj) | ||
|
||
expect(result).toBe(def) | ||
}) | ||
}) |
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,5 @@ | ||
import curry from './curry' | ||
|
||
const prop = curry((key, obj) => obj[key]) | ||
|
||
export default prop |
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,9 @@ | ||
import curry from './curry' | ||
import prop from './prop' | ||
|
||
const propOr = curry((def, key, obj) => { | ||
const val = prop(key, obj) | ||
return val === undefined ? def : val | ||
}) | ||
|
||
export default propOr |