default.txt 664 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # take the first n objects from a list
  2. take = (n, [x, ...xs]:list) -->
  3. | n <= 0 => []
  4. | empty list => []
  5. | otherwise => [x] ++ take n - 1, xs
  6. take 2, [1, 2, 3, 4, 5]
  7. # Curried functions
  8. take-three = take 3
  9. take-three [6, 7, 8, 9, 10]
  10. # Function composition
  11. last-three = reverse >> take-three >> reverse
  12. last-three [1 to 8]
  13. # List comprehensions and piping
  14. t1 =
  15. * id: 1
  16. name: 'george'
  17. * id: 2
  18. name: 'mike'
  19. * id: 3
  20. name: 'donald'
  21. t2 =
  22. * id: 2
  23. age: 21
  24. * id: 1
  25. age: 20
  26. * id: 3
  27. age: 26
  28. [{id:id1, name, age}
  29. for {id:id1, name} in t1
  30. for {id:id2, age} in t2
  31. where id1 is id2]
  32. |> sort-by \id
  33. |> JSON.stringify