paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

A handy ListOf Type #41

Closed jcouyang closed 8 years ago

jcouyang commented 8 years ago

handy ListOf[T] Type as mention in issue #32

validate it is a Array and each element type to be T

paldepind commented 8 years ago

Thank you for this contribution @jcouyang. I think including this in the library is a great idea.

What do you think about implementing the typechecking with a for-loop? I think the current implementation is a bit hard to understand.

jcouyang commented 8 years ago

@paldepind not sure if it's easier to understand now, replaced the recur with for loop, validating each item's type by constructing one. also improved the error message.

paldepind commented 8 years ago

Thank you for the PR @jcouyang. I'm finally going to merge it now and do a release :smile: