J3RN :fedora: :elixir: :emacs: on Nostr: #Haskell question: Is there a function for "reapply this function to a starting value ...
#Haskell question: Is there a function for "reapply this function to a starting value N times"? e.g. `doTimes (*2) 3 1` would return `8` ((*2) $ (*2) $ (*2) $ 1). I know I could chain take and iterate and then do a Data.List.last, but that has crumby performance for very large values of N.
Published at
2024-12-12 03:29:56Event JSON
{
"id": "0c63aafaf7ad4b02b6e9fb928a0ec086f5a40054623842aefbb0526815a80b20",
"pubkey": "eebd14d82c7521a8a88dc84281fb4f1441ac71d0241f4e0dfa3f5058a1a076b0",
"created_at": 1733974196,
"kind": 1,
"tags": [
[
"t",
"haskell"
],
[
"proxy",
"https://fosstodon.org/users/j3rn/statuses/113637732943621943",
"activitypub"
]
],
"content": "#Haskell question: Is there a function for \"reapply this function to a starting value N times\"? e.g. `doTimes (*2) 3 1` would return `8` ((*2) $ (*2) $ (*2) $ 1). I know I could chain take and iterate and then do a Data.List.last, but that has crumby performance for very large values of N.",
"sig": "918e47cabc47008bf784e2ce8e5c1211494966b73d2a0baca23f95e90dba0481f2ee1cad6b95f35fce84abdb20d1953c9e3009bbeb753b0b07d0b08fbe69ee35"
}