question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

auto generate `def` arguments

See original GitHub issue

it will be nice to have babel plugin or something like that to transform code from this

//    concatS :: String -> String -> String
const concatS = (x, y) => x + y

to this:

//    concatS :: String -> String -> String
const concatS =
def('concatS', {}, [$.String, $.String, $.String], (x, y) => x + y);

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:3
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
kedashoecommented, Apr 9, 2016

fwiw I’m chipping away at this when I can. Got some stuff working, currently turns

//  foo :: Integer -> Integer
var foo = function(x) {
  return x + 10;
};

//    concat :: a -> a -> a
const concat = (x, y) => x.concat(y);

//    head :: [a] -> Maybe a
const head = x => x.length === 0 ? Nothing() : Just(x[0]);

into

//  foo :: Integer -> Integer
var foo = def("foo", {}, [$.Integer, $.Integer], function (x) {
  return x + 10;
});;

//    concat :: a -> a -> a
const concat = def("concat", {}, [a, a, a], (x, y) => x.concat(y));;

//    head :: [a] -> Maybe a
const head = def("head", {}, [$.Array(a), $.Maybe(a)], x => x.length === 0 ? Nothing() : Just(x[0]));;

Does that all look correct (I’m in a bit of a hurry at the moment, I’ve hardly even looked at the results)? (I notice an extra ; is sneaking in haha)

I think there are a lot of options/decisions/different directions we can go, so I’m just trying to get a minimum useful product up and then we can make all those fun decisions together.

5reactions
nkrkvcommented, Feb 20, 2017

For those who’re interested in hmDef concept by @kedashoe: https://github.com/xodio/hm-def

It’s not quite complete regarding complex cases but usable enough for usual scenarios. Works fine on a hundred of functions in our project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generate function with arguments filled in when creating it?
Generate function with arguments filled in when creating it? ; import io def ; a_value): a_func = make_concrete_func(a_value) write_to_file([ ...
Read more >
Is it possible to autogenerate a TypedDict from function ...
Is it possible to autogenerate a TypedDict from function arguments?
Read more >
Is there a feature to automatically add in named parameters ...
is there any way to have the plugin automatically generate these for a new method? e.g.. I have this function: def foo(a:Int, b:...
Read more >
Defining Your Own Python Function
In this tutorial, you'll learn how to define and call your own Python function. You'll also learn about passing data to your function,...
Read more >
Don't automatically use auto parameters in C++ | Lesley Lai
Auto parameters generate templates ... In some programming languages such as ML or Rust, the type system can infer the exact type of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found