haskellcamargo / haskellcamargo/js-real-world-functional-programming

Doubt about external reference

Open
#3 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
358
Forks
14
PR merge metrics
No merged PRs in 30d

Description

In [user.js](https://github.com/haskellcamargo/js-real-world-functional-programming#do-5) example:

```javascript
const listUsers = () => User.find().asArray()
```
The `listUsers` method is using an external reference. Where `User` come from?

Is it not a good practice to pass what the method gonna need as argument?

Considering that `User` is something like:
```javascript
const User = {
find: () => ({
asArray: () => {
return ['User1', 'User2']
}
})
}
```

Then you can inject to `listUsers`

```javascript
const listUsers = User => User.find().asArray()
```
And then you can call `listUsers(User)`

What if you expect an `id` to filter the users list? (i'm not going to implement another `Users`)
but you can do something like:

```javascript
const listUsers = id => User => User.find(id)
listUsers(id)(User)
```
You got everything you need inside the method.

***Thank you for this repo, I learned a lot.***

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.