Last active
February 25, 2017 15:22
-
-
Save aliceklipper/bfee5e8e1f8ab3f8137a1fc9eb475743 to your computer and use it in GitHub Desktop.
Arrays and pure functions
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
from fs import readFile as read | |
from console import print | |
async main () : I32 | |
let raw = (await read('array.txt')).toString() | |
let split = raw.split('\n') | |
let mapper = pure (line, number) # `line`'s type inferred as `String` | |
'Line #`number + 1`: `line`' | |
# | |
No `return` keyword | |
Value of latest expression used as return value instead | |
However, it's subject of change, I'm pretty unsure of this design | |
# Also I'm unsure of syntax of passing functions as arguments | |
# | |
NB: Pure functions on arrays may be executed in parallel in different threads. | |
Should I return a Promise from `map` methon in this case? | |
Or it will be blocking operating and current thread | |
will wait until map function will be executed on every array item? | |
# | |
Oh, for multiline comments can be used exactly the same syntax as for single-line, | |
but subsequent lines must be indented relatively to the first comment line. | |
let mapped = split.map(mapper) | |
print('`mapped.join('\n')`') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment