Skip to content

chore: Extract buildin* to FunctionBuilder#291

Merged
stephenamar-db merged 1 commit intodatabricks:masterfrom
He-Pin:functionBuilder
Apr 22, 2025
Merged

chore: Extract buildin* to FunctionBuilder#291
stephenamar-db merged 1 commit intodatabricks:masterfrom
He-Pin:functionBuilder

Conversation

@He-Pin
Copy link
Contributor

@He-Pin He-Pin commented Apr 18, 2025

Motivation:

Make the buildin* helper function accessible without extending the Std() class.

Then I can just extend the FunctionBuilder, build the additionalNativeFunctions, and then pass it to the Std()'s constructor.

otherwise:

object JsonnetStdExt extends Std(Map.empty) {
  val extFunctions: Map[String, Val.Func] = Map(
    builtin("objectReplaceKey", "obj", "key", "newKey") {
      (pos, ev, o: Val.Obj, key: String, newKey: String) =>
        val bindings: Array[(String, Val.Obj.Member)] = for {
          k <- o.visibleKeyNames
          v = o.value(k, pos.fileScope.noOffsetPos)(ev)
        } yield {
          val newKeyName = if (k == key) newKey else k
          (newKeyName, new Val.Obj.ConstMember(false, Visibility.Normal, v))
        }
        Val.Obj.mk(pos, bindings)
    }
  )
}

@He-Pin
Copy link
Contributor Author

He-Pin commented Apr 21, 2025

@stephenamar-db I have rebased on the current master.

@stephenamar-db stephenamar-db merged commit b0b37c9 into databricks:master Apr 22, 2025
6 checks passed
@He-Pin He-Pin deleted the functionBuilder branch April 22, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants