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

Type.ListOf #32

Open
kwijibo opened this issue Feb 26, 2016 · 4 comments
Open

Type.ListOf #32

kwijibo opened this issue Feb 26, 2016 · 4 comments

Comments

@kwijibo
Copy link

kwijibo commented Feb 26, 2016

It would be useful to be able to define that a property of a type should be a typed list, eg:

const Shape = Type({Shape: [ListOf(Point)]})

Implementation could be something like (assuming the prototype version in the next branch)

Type.ListOf = type => list => R.all(R.is(type), list)
@paldepind
Copy link
Owner

Great idea. union-type allows one to use any validator function. So it should be possible to just define ListOf and use it like this

var ListOf = type => list => R.all(R.is(type), list)
const Shape = Type({Shape: [ListOf(Point)]})

@kwijibo
Copy link
Author

kwijibo commented Mar 16, 2016

Unfortunately this still doesn't work:
TypeError: Expecting a function in instanceof check, but got #<Object>
https://tonicdev.com/56d99860c541640d00a08d12/56e9228c007e791100e3d56a

@kwijibo
Copy link
Author

kwijibo commented Mar 16, 2016

Is ListOf a common enough modelling requirement that it would be worth adding the function to the library?

@jgoux
Copy link

jgoux commented Mar 25, 2016

I'd be very interested in this type too ! 👍

jcouyang added a commit to jcouyang/union-type that referenced this issue May 11, 2016
simple ListOf[T] Type as mention in paldepind#32

validate it is a Array and each element type to be T
jcouyang added a commit to jcouyang/union-type that referenced this issue May 11, 2016
simple ListOf[T] Type as mention in paldepind#32

validate it is a Array and each element type to be T
jcouyang added a commit to jcouyang/union-type that referenced this issue May 12, 2016
simple ListOf[T] Type as mention in paldepind#32

validate it is a Array and each element type to be T
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

No branches or pull requests

3 participants