Skip to content

Conversation

pelotom
Copy link
Contributor

@pelotom pelotom commented May 19, 2016

Type.New lets you make a type which is isomorphic to, but distinct from another type:

var ID = Type.New(String)

Type.Record lets you make a type with a single constructor which you don't have to name:

var Person = Type.Record({
  id: ID,
  name: String,
  age: Number
})

Use .from() to make instances of a Type.Record or Type.New:

var fred = Person.from({
  id: ID.from('2ialp7b4lu'), // passing a simple string here would of course be an error
  name: 'Fred',
  age: 24
})

To extract the wrapped value of a newtype, use .value:

console.log(fred.id.value) // prints '2ialp7b4lu'

@pelotom pelotom force-pushed the records-and-newtypes branch from 9a7a426 to 25ed4f7 Compare May 19, 2016 09:24
@davidchambers
Copy link
Contributor

These additions seem useful to me!

@rickmed
Copy link

rickmed commented Aug 10, 2016

me too!

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.

3 participants