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.

Add assignment operator to assign values in the middle of pipelines

See original GitHub issue

For example, we have this pipeline:

3 |> x -> x**2 |> y -> y/3 |> print

which gives us the result 3 |> 9 |> 3 |> 3. Sometimes we may want to get the value in the middle, say 9 in the above example and assign it to a variable so we can use it later (e.g. debugging).

I don’t know if something like the following possible?

3 |> x -> x**2 =: a |> y -> y/3 |> print$(a, ?)
# 9, 3

or

3 |> x -> x**2 => a |> y -> y/3 |> print$(a, ?)
# 9, 3

Thank you evhub and all the contributors for making a great language. Piping and compositing really make Python more fun =D

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
eindirancommented, Jan 10, 2020

See issue #489.

2reactions
eindirancommented, Jan 10, 2020

Note to anyone in the future trying to use the assignment operator :=: This only works in Python 3.8, so you need to pass the --target 38 to Coconut. Then make sure your interpreter is 3.8+ or you’ll end up with:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/coconut/command/util.py", line 167, in exec_func
    exec(code, glob_vars)
  File "<string>", line 1
    (lambda x: (lambda y: (_coconut_partial(print, {0: a}, 2))(y / 3))((a := x**2)))(3)
                                                                          ^
SyntaxError: invalid syntax
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipe with assignment | pipeR Tutorial
If one needs to assign the value to a symbol, just insert a step like (~ symbol) , then the input value of...
Read more >
Assignment operators - assign an expression to a variable
The assignment operator = assigns the value of its right-hand operand to a variable, a property, or an indexer element given by its...
Read more >
Assignment (=) - JavaScript - MDN Web Docs - Mozilla
The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple...
Read more >
Assignment Operators - Developer Help
The simple assignment operator "=", assigns the value on its right to the variable on its left. Compound Assignment. variable = variable op...
Read more >
Assignment and Compound Assignment
The assignment statement stores a value in a variable. Compound assignment combines assignment with another operator.
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