evilsoft / crocks

A collection of well known Algebraic Data Types for your utter enjoyment.
https://crocks.dev
ISC License
1.59k stars 102 forks source link

`getProp` of `null` value returns a `Just` #487

Closed dharmavagabond closed 4 years ago

dharmavagabond commented 4 years ago

As the title says, having something like getProp('current')({ current: null }), returns Just(null), since internally it uses the isDefined function—which only checks for undefined and not a null value. Is that the intended behavior?

dalefrancis88 commented 4 years ago

Yes this is the expected behaviour. There are a lot of scenarios where null is considered a valid value. If you want to do that you could use kleisli comp with getProp and safe

composeK(
    safe(isNotNull),
    getProp('current')
)
dharmavagabond commented 4 years ago

Ok, thanks mate.

dalefrancis88 commented 4 years ago

np, glad to help. If you want, feel free to join the gitter if you like. It's quite active

dharmavagabond commented 4 years ago

Will do, cheers!