0

This would be useful for object construction by chaining. For example, say I would like to create a DataFrame by piping a Dict to it. As in,

merge(dict1, dict2) |> DataFrame

But DataFrame here returns the type DataFrame rather than the constructor I need. How can I access the constructor? I can see the signatures with methods(DataFrame) but can't access the actual function.

1 Answer 1

1

This doesn't work for any type because the |> (pipe) method does not exist for the signature (Any, DataType).

I haven't tried with DataFrame, but the following trivial example works:

type Foo
  x::Int
end

|>(a::Any, T::DataType) = T(a)

test = 1 |> Foo
Sign up to request clarification or add additional context in comments.

2 Comments

To elaborate on Isaiah's answer, when you write a |> b, you are really calling, |>(a, b). In the example you give, this means you would be calling |>(a::Dict, b::Type{DataFrame}).
@Isaiah Thanks Isaiah. I understand that in the example I gave it accesses the type. I am wondering though if it is possible to access the constructor of the type to store in a variable. Then pipe could be used without a new method, though the pipe was really just being used as an example of a possible use case. Something like: `cnst = Foo.constructors[1]; 1 |> cnst.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.