Last active
May 21, 2020 08:40
-
-
Save 0atman/bb83f1ac495da9027ddc2bd60829217f to your computer and use it in GitHub Desktop.
Example of how nim siloes side-effecting code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httpClient | |
import strutils | |
func protocol(url: string): bool = ## ok, pure function | |
return "http://" in url | |
func get(url: string): string = ## side-effects.nim(7, 6) Error: 'get' can have side effects | |
if protocol url: | |
return newHttpClient().getContent(url) | |
proc get(url: string): string = ## This now works. `get()` must be defined as a `proc` as it causes side effects | |
if protocol url: | |
return newHttpClient().getContent(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ nim c side-effects.nim side-effects.nim(7, 6) Error: 'get' can have side effects