-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add At/Index class (#43) #48
Conversation
src/index.ts
Outdated
return new At(at => new Lens(s => SM.lookup(at, s), a => s => a.fold(SM.remove(at, s), x => SM.insert(at, x, s)))) | ||
} | ||
|
||
export function atSet<A = never>(setoid: Setoid<A>): At<Set<A>, A, boolean> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that S.member(setoid)
, S.insert(setoid)
and S.remove(setoid)
can be memoized
export function atSet<A = never>(setoid: Setoid<A>): At<Set<A>, A, boolean> {
const member = S.member(setoid)
const insert = S.insert(setoid)
const remove = S.remove(setoid)
return new At(
at => new Lens(s => member(s)(at), a => s => (a ? insert(at, s) : remove(at, s)))
)
}
Thanks @leighman
Since this library is a porting of Scala's monocle I'd stick with monocle definitions
Let's move them in specific files so that users are not forced to load unwanted dependencies, something along the lines of
What do you mean, for example |
Like that? With
Yup, whether it should be |
Yes, if we add a export class At<S, I, A> {
...
/** lift an instance of `At` using an `Iso` */
fromIso<T>(iso: Iso<T, S>): At<T, I, A> {
return new At(i => iso.composeLens(this.at(i)))
}
} then people can build an const isoStrMap = <A = never>() => new Iso<Record<string, A>, SM.StrMap<A>>(s => new SM.StrMap(s), a => a.value)
const atRecord = atStrMap<string>().fromIso(isoStrMap()) |
Added |
Great, thanks.
Yes please, let's rename them to Are |
Renamed.
I agree. Misunderstood your earlier comment. Removed them. |
Thanks a lot @leighman |
Cheers! |
Thought I'd give this a try - I think I've understood correctly...
Added At for StrMap and Set based on the monocle module. Noticed that PureScript has
set
always with aMaybe
- do we want that here instead?Is it worth adding
atRecord
oratOption
as PS does?Wasn't sure about the composition stuff, would appreciate some guidance on that, then could probably look at doing
Index
too.