1
$\begingroup$

I want to use the function apply (or something even better).

x//f

with a function that has more than one parameter. Here is how it works with one parameter.

data = Dataset[<|"a" -> <|"x" -> 1, "y" -> 2, "z" -> 3|>, 
   "b" -> <|"x" -> 5, "y" -> 10, "z" -> 7|>|>]
pullz[x_] := x[[All, "z"]]
data // pullz

Here is the two parameter version

pull[x_, c_] := x[[All, c]]
data // pull

Here is the desired result

pull[data, "z"]

I want to add the parameter "z" to the two parameter version and still use //

Thanks for the help: Here is what I actually used in my code, as learned from the input here

r1 = tables // pull[#, "TABLE_NAME"] & // 
  Select[#, StringStartsQ[#, "Patient"] &] &

I added the suggestion, My tables actually comes from the SQL query:

SELECT * FROM Experiments.INfORMATION_SCHEMA.TABLES WHERE TABLE_TYPE \
= 'BASE TABLE'

Here is the modified Mathematica code

pull[c_][x_] := pull[x, c]
tNames = tables // 
  pull["TABLE_NAME] // Select[StringStartsQ[" Patient "]]
$\endgroup$
  • $\begingroup$ data//pull[#, "z"]& $\endgroup$ – user6014 Aug 8 at 15:01
  • $\begingroup$ @user6014 I got so close, I tried that but without the & $\endgroup$ – Harlan Nelson Aug 8 at 15:17
  • $\begingroup$ Slots (#) almost always need a trailing & somewhere. $\endgroup$ – user6014 Aug 8 at 15:17
  • 8
    $\begingroup$ I would suggest you define the operator form pull[c_][x_] := pull[x,c]. Then you can write the last line as r1 = tables // pull["TABLE_NAME"] // Select[StringStartsQ["Patient"]] (note that both Select and StringStartsQ also have an operator form). The nice thing about operator forms is that you can omit the # & & stuff in many cases. $\endgroup$ – Lukas Lang Aug 8 at 15:42
  • 1
    $\begingroup$ A roundabout way :) : data // List // Append@"x" // Apply@pull $\endgroup$ – Michael E2 Aug 8 at 16:14