Skip to content

Compare two complex templates #525

Answered by holzensp
niddar asked this question in Q&A
Jun 13, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

This doesn't quite seem right (if value > other, comparison ends up being false and the fold continues). I'd make comparison nullable to distinguish between not-yet-decided and decided-false.

hidden genericCompare: (Typed, Typed) -> Boolean = (value1, value2) ->
  value1.getClass() == value2.getClass() &&
    let (m1 = value1.toMap())
    let (m2 = value2.toMap())
      m1.fold(null, (comparison, key, value) ->
        comparison ??
          let (other = m2[key])
            if (value == other) null
            else
              if (value is Comparable) value < other
              else if (value is Typed) genericCompare.apply(value, other)
              else false
      ) ?? false

Be m…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@holzensp
Comment options

Answer selected by niddar
@niddar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants