JohnAD / nullable

Null-able (and error-able) basic types for Nim.
MIT License
1 stars 0 forks source link

Need a Nullable[T] type for generic usage with objects #3

Open JohnAD opened 5 years ago

JohnAD commented 5 years ago

Example code from Option[T]:

https://github.com/nim-lang/Nim/blob/d53ab9e5c857d47b8ea9643a2cf0235f3486afa0/lib/pure/options.nim

However, I will limit it to pure 'objects'. No pointers or ref. No basic types. Strictly objects.

And, just like the regular nullable types, the following WILL work if at all possible:

type
  User = object
    name: string
    age: int

var u: Nullable[User] = User(name: "Larry")
var x: Nullable[User] = nothing(User)
var y: Nullable[User] = null(User)
var z: Nullable[User] = ValueError(msg: "something went wrong")
JohnAD commented 5 years ago

half-done. Will do more soon.

JohnAD commented 5 years ago

Being made for usable with anything, not just objects. See #6