Skip to content

Instantly share code, notes, and snippets.

@julien-truffaut
Last active September 16, 2020 05:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien-truffaut/2282c8db6c9935668433dfe0be95f689 to your computer and use it in GitHub Desktop.
Save julien-truffaut/2282c8db6c9935668433dfe0be95f689 to your computer and use it in GitHub Desktop.
Proposal for new optics names

Frieldly optics name proposals

Here are some proposal for optics names. The goal is to give a better intuition to beginners, especially people with no FP experience.

  • Setter -> Replace, Modify, Write
  • Fold -> Aggregate
  • NonEmptyFold -> Reduce
  • Getter -> Read
  • ReadOnlyOptional -> ???
  • Traversal -> ???
  • NonEmptyTraversal -> ???
  • Optional -> Find
  • Prism -> Subset, Select, Branch
  • Lens -> Field, Focus
  • Iso -> Equivalent, Equivalence, Conversion

Insipration from tofu-optics

@ivanopagano
Copy link

Setter -> Write iff Getter -> Read
Prism -> Inspect?

also Equivalence instead of Equivalent? or why not Conversion?

I'm thinking also in terms of how the naming might help to define meaningful variable names for actual code.

I find quite frustrating to come up with unique yet meaningful names for the final outcome of [composed] optics... I don't actually love the -L suffix rule...

E.g.

case class Address(street: Street)

val readStreet: Read[Address, Street] = ???
val writeStreet: Write[Address, Street] = ???
val streetFocus: Focus[Address, Street] = ???

Does it makes any sense?

@julien-truffaut
Copy link
Author

julien-truffaut commented Feb 10, 2020

@ivanopagano good ideas. Regarding Write, it might give the wrong intuition that you can insert a value while you can only replace an existing one.

I like Read, do you have an idea for a Getter than can fail (e.g. read-only Optional)?

@ivanopagano
Copy link

ivanopagano commented Feb 10, 2020

Look? @julien-truffaut?

Well, now that I think of it there's a while mini-vocabulary we can borrow form the db-world

  • View
  • Projection
  • Update
  • ...

Also there might be a place for If ? e.g. the R.O.Optional?

@DavidGregory084
Copy link

Prism -> Classify?
Fold -> Gather / Collect / Summarize?
Iso -> Exchange / Synonym?

@DavidGregory084
Copy link

Iso -> Equate?

@DavidGregory084
Copy link

Prism -> Identify?

@psisoyev
Copy link

How about:

Fold -> Aggregate
NonEmptyFold -> Reduce

@julien-truffaut
Copy link
Author

Should the optics be names or verbs? I guess we should be consistent (Reduce vs Reducer)

@ivanopagano
Copy link

Should the optics be names or verbs? I guess we should be consistent (Reduce vs Reducer)

Personally I'd go for verbs, which to me sounds simpler and more natural for the majority of cases.
Yet I can see that, as alwasys, it depends on the term used... if you choose Focus... is that a noun or a verb? View? Update?
Project might cause misunderstanding wrt Projection...

🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment