~/talk

Advanced Swift Optics

Talkat Swift Heroes 2018 · on Friday, 2018-11-09· [functional-programming, swift]
links:none on file
slides:none on file

Explains how to use concrete optics in Swift to manipulate deeply nested value types: builds Lens from writable key paths, creates a dictionary-key lens and a zipped lens for simultaneous fields, defines Prism for enum cases with match/build and tryModify, and generalizes both as an Affine to target optional or indexed elements (first matching predicate in an array). Shows composing these optics to locate a transaction outcome through enum → dictionary → array → field and update its balance, with working Swift playground code and pattern examples.

AI-written summary · about

  1. 0:00Intro
  2. 0:12Advanced Swift Optics
  3. 2:051. Total: Thay return an output for every Input. 2. Deterministic: They return the same output for the same input. 3. Pure: Their only effect is computing the output.
  4. 5:16Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowcharts; they'll be obvious.
  5. 6:13domain modeling • Ul modeling • transitional information • intent representation
  6. 10:35separation of representation from interpretation • the former at the core, the latter at the boundary • readable, testable, maintainable • not just for functional programming
  7. 12:32they can get messy and complex • lots of nesting • we usually operate on tiny parts... ...but we need to transform the whole
  8. 14:17types (usually structs) • encapsulate various kinds of relationships between data structures • for example, "focusing": • relationship between a data structure and
  9. 15:18different sources and different platforms use different names • "Profunctor Optics - Modular Data Accessors by Matthew Pickering, Jeremy Gibbons, and Nicolas Wu • "Don't Fear the Profunctor Optics! GitHub repo
  10. 16:34like KeyPath (not a coincidence) • simplified representation • full representations has 2 more parameters: • generic change on both Root and Value
  11. 36:13Functional Programming rocks • even if just a bit • Well-defined data structures are the key to dear, testable and maintainable code • Optics: a useful tool to operate on data structures in a generic way • Lens: structs and classes
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.