Skip to content

Matrix that shows which Sanctuary ADT's implements which Type Classes

License

Notifications You must be signed in to change notification settings

dotnetCarpenter/sanctuary-adt-matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sanctuary ADT Matrix

npm

Usage:

$ npx sanctuary-adt-matrix
Type Class Pair Maybe Either Future
Setoid
Ord
Semigroupoid
Category
Semigroup
Monoid
Group
Filterable
Functor
Bifunctor
Profunctor
Apply
Applicative
Chain
ChainRec
Monad
Alt
Plus
Alternative
Foldable
Traversable
Extend
Comonad
Contravariant

Using the matrix API

Test Sanctuary's Algebraic Data Types (ADT) for Type Class support.

The API is unstable and will probably change between minor versions.

const { adts, typeClassTests } = require ('sanctuary-adt-matrix');

// adts :: Array (Array (String Adt))
[
  ['Pair'  , Adt],
  ['Maybe' , Adt],
  ['Either', Adt],
  ['Future', Adt]
]

// typeClassTests :: Array (Array (String Adt) -> Array (String))
typeClassTests [0] (adts) // -> [ 'Setoid', '✅', '✅', '✅', '❌' ]

Adding an ADT

Currently (1.0.1), you need to change two places. To add a new ADT, you need to edit index.js, require the new ADT and add it to the adts array.

const adts = [
  ['Pair'  , S.Pair ('') ('')],
  ['Maybe' , S.Just ('')],
  ['Either', S.Right ('')],
  ['Future', Future (reject => resolve => () => {})]
];

The tuple is [name:String, instance:ADT].

Then you need to set padding in view/markdown.js in the view function.

${S.joinWith ('\n')
             (S.map (r => `| ${r} |`)
                    (row ([13, 3, 4, 5, 5]) (S.map (test => test (adts))
                                                   (typeClassTests))))}

The padding is [13, 3, 4, 5, 5].

[
  13, // = longest Type Class word
  3,  // = padding for Pair column
  4,  // = padding for Maybe column
  5,  // = padding for Either column
  5,  // = padding for Future column
      // add padding for your ADT column - usually number of characters minus 1
]

About

Matrix that shows which Sanctuary ADT's implements which Type Classes

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published