Return Nothing() If The Object passed To Get() Is Null
See original GitHub issueWould it be reasonable for get
to have the above behaviour? I’d like to use this function as the ‘gateway’ for converting the values in a function pipeline to Maybe
s. Currently I’m a querying a datasource using highland
for some JSON that may return null
. At the moment I do this:
var _ = require('highland');
var R = require('ramda');
var S = require('sanctuary');
_(datasource)
.map(R.compose(R.chain(S.get('b')), R.chain(S.get('a')), S.toMaybe))
.reject(S.Nothing().equals)
It would be nice not to have to do that initial map with toMaybe
and the subsequent call to R.chain so it would look like this:
_(datasource)
.map(R.compose(R.chain(S.get('b')), S.get('a')))
.reject(S.Nothing().equals)
Or even nicer once v0.5.0 of Sanctuary drops:
_(datasource)
.map(S.gets(['a', 'b']))
.reject(S.Nothing().equals)
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Should functions return null or an empty object? - Stack Overflow
An empty object implies data has been returned, whereas returning null clearly indicates that nothing has been returned. Additionally, returning ...
Read more >Is it better to return NULL or empty values from functions ...
In FindPerson() , returning NULL seems like a better fit. Regardless of whether or not NULL or an empty Person Object ( new...
Read more >Stop Returning Null in Java - Code by Amir | Amir Boroumand
In Java, a null value can be assigned to an object reference of any type to indicate that it points to nothing. Calling...
Read more >How to return a empty object when linq query yields nothing ...
I'm trying to query the database using linq query and the FirstOrDefault yields null value. Is there a way I can return a...
Read more >null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Watch out. That’s what happened to @buzzdecafe and me too with Ramda. A year later, there are 1600+ commits from 62 different contributors, 31 open issues and 9 unresolved pull requests out of over a thousand total issues/PRs raised! It’s a fun ride, but a little scary too! 😄
I’m quite happy with this breakdown. Ramda pushes things a fair way towards stronger typing of functions, but makes some pragmatic compromises familiar to Javascript developers. Sanctuary pushes a little closer to languages like ML and Haskell. Since they can play well together, a user can decide which level is appropriate for herself.
Sounds good. Thanks guys.