import { curry } from '@typed/lambda'
/**
* Get the value of a property if present or use default value.
* @param defaultValue :: a
* @param key :: PropertyKey
* @param obj :: { [PropertyKey]?: a }
* @returns :: a
*/
export const propOr: {
(defaultValue: A, key: K, obj: { [Key in K]: A }): A
(defaultValue: A, key: K): (obj: { [Key in K]: A }) => A
(defaultValue: A): {
(key: K, obj: { [Key in K]: A }): A
(key: K): (obj: { [Key in K]: A }) => A
}
} = curry(__propOr) as {
(defaultValue: A, key: K, obj: { [Key in K]: A }): A
(defaultValue: A, key: K): (obj: { [Key in K]: A }) => A
(defaultValue: A): {
(key: K, obj: { [Key in K]: A }): A
(key: K): (obj: { [Key in K]: A }) => A
}
}
function __propOr(defaultValue: A, key: K, obj: { [Key in K]: A }): A {
return obj.hasOwnProperty(key) ? obj[key] : defaultValue
}