question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return Nothing() If The Object passed To Get() Is Null

See original GitHub issue

Would 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 Maybes. 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:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
CrossEyecommented, Apr 20, 2015

I was excited to see this issue, @svozza. I had not realized that Sanctuary is being used outside a handful of Plaid projects.

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! 😄

The question is whether it is the caller’s responsibility to provide appropriate values or whether certain functions should be more forgiving. Certain Ramda functions treat null/undefined as an empty object. Currently Sanctuary takes a stricter stance.

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.

0reactions
svozzacommented, Apr 20, 2015

Sounds good. Thanks guys.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found