Skip to content

Instantly share code, notes, and snippets.

@ImkeF
Last active December 17, 2018 13:22
Show Gist options
  • Select an option

  • Save ImkeF/f706fb8e18c75011db89009d0b32f140 to your computer and use it in GitHub Desktop.

Select an option

Save ImkeF/f706fb8e18c75011db89009d0b32f140 to your computer and use it in GitHub Desktop.
let func =
(function as function) =>
let
function_ = function,
Metadata = (functionType) as record =>
let
Help = Value.Metadata(if functionType is type then functionType else Value.Type(functionType))
in
Help,
TextType = (t as type) as text =>
let
nonNullableType = Type.NonNullable(t),
TypeDescription = if Type.Is(nonNullableType, type binary) then "binary"
else if Type.Is(nonNullableType, type date) then "date"
else if Type.Is(nonNullableType, type datetime) then "datetime"
else if Type.Is(nonNullableType, type datetimezone) then "datetimezone"
else if Type.Is(nonNullableType, type duration) then "duration"
else if Type.Is(nonNullableType, type function) then "function"
else if Type.Is(nonNullableType, type list) then "list"
else if Type.Is(nonNullableType, type logical) then "logical"
else if Type.Is(nonNullableType, type none) then "none"
else if Type.Is(nonNullableType, type null) then "null"
else if Type.Is(nonNullableType, type number) then "number"
else if Type.Is(nonNullableType, type record) then "record"
else if Type.Is(nonNullableType, type table) then "table"
else if Type.Is(nonNullableType, type text) then "text"
else if Type.Is(nonNullableType, type time) then "time"
else if Type.Is(nonNullableType, type type) then "type"
else if Type.Is(nonNullableType, type action) then "action"
else if Type.Is(type anynonnull, nonNullableType) then "any"
else error "Unknown type",
TypeString = if TypeDescription = "any" then
if Type.IsNullable(t) then
"any" else "anynonnull"
else if Type.IsNullable(t) then
"nullable " & TypeDescription
else TypeDescription
in
TypeString,
FunctionSignature = (function as function) as text =>
let
functionName = "",
Parameters = Record.ToTable(Type.FunctionParameters(Value.Type(function))),
ParameterTypeName = Table.AddColumn(Parameters, "Type Name", each TextType([Value])),
Cleanup = Table.SelectColumns(ParameterTypeName, {"Name", "Type Name"}),
AsList = Table.ToList(Cleanup, Combiner.CombineTextByDelimiter(" as ")),
MinParameters = Type.FunctionRequiredParameters(Value.Type(function)),
RequiredParameters = List.FirstN(AsList, MinParameters),
RequiredString = Text.Combine(List.Transform(RequiredParameters, (p) => p & ", ")),
OptionalParameters = List.Skip(AsList, MinParameters),
OptionalString = Text.Combine(List.Transform(OptionalParameters, (p) => "optional " & p), ", "),
RequiredClean = if List.Count(OptionalParameters) = 0 then Text.TrimEnd(RequiredString, {" ", ","}) else RequiredString,
OptionalClean = Text.TrimEnd(OptionalString, {" ", ","}),
ReturnTypeName = TextType(Type.FunctionReturn(Value.Type(function))),
Signature = Text.Format("#[name](#[required]#[optional]) as #[returnType]",
[name=functionName, required=RequiredClean, optional=OptionalClean, returnType=ReturnTypeName])
in
Signature,
Description = Metadata(function_) &[Signature = FunctionSignature(function_)]
in
Description
, documentation = [
Documentation.Name = " Documentation.FieldValues
", Documentation.Description = " Shows the values of the documentation-fields and the signature of a function
" , Documentation.LongDescription = " Shows the values of the documentation-fields and the signature of a function
", Documentation.Category = " Documentation
", Documentation.Source = " local
", Documentation.Author = " Imke Feldmann: www.TheBIccountant.com .
", Documentation.Examples = {[Description = "
" , Code = "
", Result = "
"]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment