mlhaufe/brevity

Consider structural matching on traits

Closed this issue · 1 comments

const Point = Data({ Point2: ['x', 'y'], Point3: ['x', 'y', 'z'] })

const print = Trait(Point, {
    Point2({ x, y }) { return `(${x}, ${y})` },
    Point3({ x, y, z }) { return `(${x}, ${y}, ${z})` }
})

Should traits support structural matching and not require a variant instance?

print(Point2(1,2))
print({x:1 ,y: 2})
print([1,2]) // this is probably too ambiguous

Subsumed by #39