Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow null or undefined values. #14

Closed
wants to merge 1 commit into from
Closed

Disallow null or undefined values. #14

wants to merge 1 commit into from

Conversation

DylanRJohnston
Copy link

I think supplying undefined or null values to the constructor should throw a type error. If a field can be null then it should be modelled with a maybe type.

This allows the constructors to play more nicely with other parsing functions.

@DylanRJohnston
Copy link
Author

DylanRJohnston commented Apr 27, 2017

For example

const encase = f => x => {
  try {
    return Right(f(x))
  } catch(error) {
    return Left(error)
  }
}

// objectToMessage :: Object -> Either Error OutGoingMessage
const objectToMessage = encase({id, data, requestType, requestUUID} => 
  OutgoingMessage(id, data, requestType, requestUUID)
)

So we handle object being null and any of the fields missing.

@safareli
Copy link
Member

I think supplying undefined or null values to the constructor should throw a type error. If a field can be null then it should be modelled with a maybe type.

We shouldn't disallow null values. if you don't want to use null it's your choice you can use whatever you want. if you want type checking for sum types check this

Also with this restriction you are trying to bring in, we can't define valid Maybe type using daggy as Maybe.Just(null) will throw.

So I don't think this is the change we should apply.

@DylanRJohnston
Copy link
Author

That's a good point. Hadn't considered constructors without any fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants