Skip to content

Instantly share code, notes, and snippets.

@deusaquilus
Last active June 18, 2020 09:05
Show Gist options
  • Save deusaquilus/290c9327bce59e11952ac9aebdba0e72 to your computer and use it in GitHub Desktop.
Save deusaquilus/290c9327bce59e11952ac9aebdba0e72 to your computer and use it in GitHub Desktop.
ApplyMap via Gin and Tonic
// ********** Before: **********
// a.map(b => c).*join(d).on((iA, iB) => on)
// a.*join(d).on((b, iB) => on[iA := c]).map(t => (c[b := t._1], t._2))
// Quat Equivalence: a.quat == b.quat == iA.quat
case Join(tpe, DetachableMap(a, b, c), d, iA, iB, on) =>
val onr = BetaReduction(on, iA -> c)
val t = Ident("t")
val t1 = BetaReduction(c, b -> Property(t, "_1"))
val t2 = Property(t, "_2")
Some(Map(Join(tpe, a, d, b, iB, onr), t, Tuple(List(t1, t2))))
// ********** After: **********
// === Conceptual Example ===
// Instead of combining gin and tonic, pour raw spirit with tonic in a cup and transform the spirit
// inside of the tup into tonic.
//
// spirits.map(spirit => ginifySpirit).join(tonics).on((iGin, iTonic) => on)
// spirits.join(tonics).on((spirit, tonic) => on[iGin := ginifySpirit]).map(t:Tuple[(Spririt, Tonic)] => (ginifySpirit[spirit := t._1], t._2)) :Tuple[(Gin, Tonic)]
case Join(tpe, DetachableMap(spirits, spirit, ginifySpirit), tonics, iGin, iTonic, on) =>
val onr = BetaReduction(on, iGin -> ginifySpirit)
val t = Ident("t")
val t1 = BetaReduction(ginifySpirit, spirit -> Property(t, "_1"))
val t2 = Property(t, "_2")
Some(Map(Join(tpe, spirits, tonics, spirit, iTonic, onr), t, Tuple(List(t1, t2))))
/**
* Notes for the example above. Gin and Tonic were used as prototypical
* examples of things that "are joined". In the table form, they are alude to the following
* tonics is Query[Tonic], tonic is Tonic
* gins is Query[Gin], is Gin
* spirits is Query[Spirit], spirit is Spirit instance
*
* ginifySpirit is some f:Spirit => Gin
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment