Last active
February 4, 2017 00:44
-
-
Save xaviervia/74ed142bf08afdba22e690270798baaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createType = name => { | |
const of = x => Object.freeze({ | |
'@@type': name, | |
fold: f => f(x), | |
map: f => of(f(x)), | |
inspect: () => `${name}(${x})` | |
}) | |
return {of} | |
} | |
const Left = createType('Left') | |
const x = {a: 1} | |
Left.of(x).map(({a}) => a + 1) |
Works for me π, but maybe we want to take it a step forward and really define the property in the object as a non-enumerable, non-configurable, non-writable property? Completely frozen and unchangeable.
Sure.
Well apparently that's already the case just because they are Symbols π
https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/
Will add freeze
π
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How 'bout: