Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
26
Task/Higher-order-functions/Lily/higher-order-functions.lily
Normal file
26
Task/Higher-order-functions/Lily/higher-order-functions.lily
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
define square(x: Integer): Integer
|
||||
{
|
||||
return x * x
|
||||
}
|
||||
|
||||
var l = [1, 2, 3] # Inferred type: List[Integer].
|
||||
|
||||
# Transform using a user-defined function.
|
||||
print(l.map(square)) # [1, 4, 9]
|
||||
|
||||
# Using a built-in method this time.
|
||||
print(l.map(Integer.to_s)) # ["1", "2", "3"]
|
||||
|
||||
# Using a lambda (with the type of 'x' properly inferred).
|
||||
print(l.map{|x| (x + 1).to_s()}) # ["2", "3", "4"]
|
||||
|
||||
# In reverse order using F#-styled pipes.
|
||||
Boolean.to_i |> [true, false].map |> print
|
||||
|
||||
define apply[A, B](value: A, f: Function(A => B)): B
|
||||
{
|
||||
return f(value)
|
||||
}
|
||||
|
||||
# Calling user-defined transformation.
|
||||
print(apply("123", String.parse_i)) # Some(123)
|
||||
Loading…
Add table
Add a link
Reference in a new issue