hemanth / functional-programming-jargon

Jargon from the functional programming world in simple terms!
http://git.io/fp-jargons
MIT License
18.58k stars 1.02k forks source link

Add definition for thunk #181

Closed kr5hn4 closed 3 years ago

jethrolarson commented 6 years ago

I found this definition which may make a good basis:

https://www.techopedia.com/definition/2818/thunk

Nullary functions (functions which do not take arguments) in functional programming are referred to as thunk. Thunks simulate lazy evaluation and delay the function argument computation.

We can then add a little explanation: Thunks can be used to delay expensive computation until the values are needed.

I would also avoid side effects in the example.

You can use something like

const getBigNumber = () => factorial(1000000);

To represent something that could take a while to compute

On Sun, Apr 22, 2018, 9:42 PM hemanth.hm notifications@github.com wrote:

@hemanth commented on this pull request.

In readme.md https://github.com/hemanth/functional-programming-jargon/pull/181#discussion_r183275658 :

@@ -535,6 +536,19 @@ const randIter = rand() randIter.next() // Each execution gives a random value, expression is evaluated on need.

+## Thunk + +A thunk is another word for a function used to inject an additional calculation into another function (or simply a function that is returned by another function). Thunks are primarily used to delay a calculation until its result is needed, or to insert operations at the beginning or end of the other function.

Can get bit more better I feel, what say @jethrolarson https://github.com/jethrolarson ?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/hemanth/functional-programming-jargon/pull/181#pullrequestreview-114242009, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB-4PXowD4J4ziK8rUyoAxDEuWD_JYZks5trVvOgaJpZM4TZ__B .

jethrolarson commented 6 years ago

That's quite good. We can probably drop "subroutine" as in the context of functional programming there's no destinction

On Wed, Apr 25, 2018, 6:51 PM hemanth.hm notifications@github.com wrote:

@hemanth commented on this pull request.

In readme.md https://github.com/hemanth/functional-programming-jargon/pull/181#discussion_r184251921 :

@@ -535,6 +536,19 @@ const randIter = rand() randIter.next() // Each execution gives a random value, expression is evaluated on need.

+## Thunk + +A thunk is another word for a function used to inject an additional calculation into another function (or simply a function that is returned by another function). Thunks are primarily used to delay a calculation until its result is needed, or to insert operations at the beginning or end of the other function.

Sounds better, thanks!

We could use const getBigNumber = () => factorial(1000000); see the comment below.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/hemanth/functional-programming-jargon/pull/181#discussion_r184251921, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB-4O9f0CJK13jmW4-kzjNujT_pAgfJks5tsSgOgaJpZM4TZ__B .

jethrolarson commented 3 years ago

Closing as stale. Reopen if you want to be considered again.