Skip to content

Conversation

@bch29
Copy link

@bch29 bch29 commented Dec 15, 2020

Adds basic lenses to the standard library, along with a macro for deriving lenses for record fields

let lens = import! std.lens

type MyRecord = {
    x: Int,
    y: String
}

let _x = lens! lens MyRecord x
let _y = lens! lens MyRecord y

The main reason I want this in upstream is so that I can use the lens! macro without the gluon language server complaining at me. I chose to implement lenses as a newtype wrapper here. The downside to this is that if this is ever expanded into a proper lens library, these lenses won't be able to compose with other optics. It may be best to just omit the standard library component of this PR altogether. The macro will work if you give it any module containing a make function with the right type.

A caveat of this macro implementation is that it doesn't work with types that have type arguments.

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.

1 participant