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

interop with unique structures like immutable.js #24

Open
jasonkuhrt opened this issue Nov 1, 2014 · 2 comments
Open

interop with unique structures like immutable.js #24

jasonkuhrt opened this issue Nov 1, 2014 · 2 comments

Comments

@jasonkuhrt
Copy link

I am curious what thoughts you have about supporting something like immutable.js where the structural typing would make sense to the user but technically fail because contracts.js would not know how to work with immutable.js objects.

It would be useful if we could teach contracts.js new tricks.

@disnet
Copy link
Owner

disnet commented Nov 4, 2014

So I haven't used immutable.js too much yet but this should just be a contract on the get/set interface right?

import @ from "contracts.js"

var Immutable = require('immutable');

@ let NumMap = {
    get: (Str) -> Num,
    set: (Str, Num) -> NumMap
}

@ () -> NumMap
function makeMap() {
    return Immutable.Map({
        a:"foo"
    });
}

var map = makeMap();

// contract violation because "foo" is a string
console.log(map.get("a"));

I think this at least gets the basics working. We might like some sweeter syntax though:

@ () -> Map Str => Num
function makeMap() {
    return Immutable.Map({
        "a": 1,
        "b": 2
    });
}

So perhaps we need a nice way to register new syntax?

@jasonkuhrt
Copy link
Author

Some sort of extensible system would be great. I mean, at some point this gets type-y but maybe there is a light-weight way to create definitions. Unfortunately doubt I'll have time to contribute thoughts to this any time soon but will keep my eye on this project. Feel free to close!

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

2 participants