-
Notifications
You must be signed in to change notification settings - Fork 4
Piping
This page explains the use of the ->, >>, and ?> operators.
The -> operator takes a value, on the left, and insets it into a function, on the right. So for example 5 -> triangularNumber is just the same as triangularNumber 5.
This is useful because it allows us to talk about operations on data from left to right. An expression like "hElLo wOrlD" -> toLowerCase -> reverse -> capitalizeInitials -> reverse is easier to read, and for you to evaluate as "hellO worlD", than if it was written as reverse capitalizeInitials reverse toLowerCase "hElLo wOrlD".
Instead of a function, we can write an expression which uses the word that: for example 3 -> that + 5 -> that * that will evaluate to 64.
This takes a list on the left and a function on the right, and returns the result of applying the function to each element of the list. So [1, 2, 3, 4, 5] >> triangularNumber would evaluate to [1, 3, 6, 10, 15].
Again, we can use the that keyword to write mapping expressions: [1, 2, 3, 4, 5] >> that + 5 >> that * that would evaluate to [36, 49, 64, 81, 100].
This takes a list on the left and a function returning a boolean value on the right, and returns those elements for which the application of the function to the element returns true. So for example [1, 2, 3, 4, 5] ?> that % 2 == 1 will select the odd elements and return [1, 3, 5].
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.
- Getting started
- Language basics
- The type system and built-in functions
- Functional Pipefish
- Encapsulation
- Imperative Pipefish
-
Imports and libraries
- The crypto/aes library
- The crypto/bcrypt library
- The crypto/rand library
- The crypto/rsa library
- The crypto/sha_256 library
- The crypto/sha_512 library
- The database/sql library
- The encoding/base_32 library
- The encoding/base_64 library
- The encoding/csv library
- The encoding/json library
- The files library
- The fmt library
- The html library
- The image library
- The image/bmp library
- The image/color library
- The image/jpeg library
- The image/png library
- The lists library
- The markdown library
- The math library
- The math/big library
- The math/cmplx library
- The math/rand library
- The net/http library
- The net/mail library
- The net/smtp library
- The net/url library
- The os/exec library
- The path library
- The path/filepath library
- The reflect library
- The regexp library
- The strconv library
- The strings library
- The terminal library
- The time library
- The unicode library
- Advanced Pipefish
- Developing in Pipefish
- Deployment
- Appendices