HadesLang Doc
  • Overview
  • Getting Started
    • Installing Hades
    • Basic Syntax
    • Coding Conventions
  • Language Spec
    • Foundation
      • Types
      • Built-in functions
    • Operators
      • Comparison and equality
      • Logical operators
      • Bitwise operators
      • Compound Assignment Operators
      • Operator overloading
    • Control flow
      • Conditions
      • Loops
      • Exception handling
      • Ternary and nullcheck operators
      • Pipelines
    • Classes and variables
      • Declaring variables
      • Declaring classes
      • Declaring structs
      • Declaring protos
      • Declaring arrays
      • Type conversions in simple variable types
    • Actors
      • Message passing
      • GenServer
      • Channels
    • Functions and lambdas
      • Declaring functions
      • Declaring lambdas
    • Functions of simple types
      • int
      • string
      • float
      • bool
      • atom
      • pid
    • Other
      • Annotations
      • Comments
      • Preprocessor statements
      • Reflection
      • Script file arguments
      • this keyword
  • Core Libraries
    • Standard library
      • std:io
        • console
        • file
        • directory
      • std:exceptions
      • std:int
      • std:internals
        • annotations
          • findMethod
          • findMethodInProto
          • findMethods
          • findMethodsInProto
        • function
      • std:collections
        • map
        • list
      • std:math
        • math
        • constants
        • matrix
      • std:networking
      • std:os
      • std:params
      • std:string
      • std:sql
    • Extra libraries
      • mssql:client
  • Other
    • Tools
    • Examples
    • Todos
Powered by GitBook
On this page
  • Source
  • Pipeline target with only one parameter
  • Example
  • Pipeline target with multiple parameters
  • Example
  • Pipelines in variable assignment
  • Example
  • List functions with pipelines
  1. Language Spec
  2. Control flow

Pipelines

Pipelines in Hades are a neat way to write out nested methods.

with list fixed from std:collections
with console from std:io

var fruits = list.of({"Apple", "Banana", "Mango", "Kiwi", "Avocado"})

fruits
|> map({x => x.toLower()})
|> filter({x => x.startsWith("a")})
|> forEach(??, {x => console.out(x)})

//As opposed to

forEach({x => console.out(x)}, filter({x => x.startsWith("a")}, map({x => x.toLower()}, fruits)))
//map(lambda, list), filter(lambda, list) and forEach(lambda, list) are static methods from the list class

//Or even

fruits.map({x => x.toLower()}).filter({x => x.startsWith("a")}).forEach({x => console.out(x)})
//map(lambda), filter(lambda) and forEach(lambda) are methods from the list class

Source

In Hades, the source of a pipeline can be any variable or statement. The source is the input parameter for the next pipeline statement.

Pipeline target with only one parameter

Example

{"Mango", "Avocado", "Orange", "Apple"}
|> sort
//is being converted to sort({"Mango", "Avocado", "Orange", "Apple"})

Pipeline target with multiple parameters

Example

{"Mango", "Avocado", "Orange", "Apple"}
|> map(??, {x=>x.toLower()})

//is being converted to map({"Mango", "Avocado", "Orange", "Apple"}, {x=>x.toLower()})

Pipelines in variable assignment

Example

var lowerList = {"Mango", "Avocado", "Orange", "Apple"}
                |> map(??, {x=>x.toLower()})

List functions with pipelines

One can import the functions defined in list as fixed and use them in pipelines on lists.

with list fixed from std:collections
with console from std:io

var fruits = list.of({"Apple", "Banana", "Mango", "Kiwi", "Avocado"})

fruits
|> map({x => x.toLower()})
|> filter({x => x.startsWith("a")})
|> forEach({x => console.out(x)})

/*
Output:
apple
avocado
*/
PreviousTernary and nullcheck operatorsNextClasses and variables

Last updated 5 years ago