El pipeline en F#
|> alimenta el valor izquierdo hacia adelante; los datos se leen en orden de flujo.
// |> feeds the left value to the right function: data flows forward.
let weightsKg = [28.4; 31.0; 19.7; 35.2; 22.1]
let heavyCount =
weightsKg
|> List.filter (fun w -> w > 25.0)
|> List.length
printfn "Hives ready for winter: %d" heavyCount
// Without the pipe the same code reads inside out.
let total = List.sum (List.map (fun w -> w * 1000.0) weightsKg)
printfn "Total grams the hard way: %.0f" total
weightsKg |> List.max |> printfn "Heaviest: %.1f kg"
Cómo funciona
weightsKg |> List.filter ... |> List.lengthse lee como oración.- La versión sin pipe anida de adentro hacia afuera — mismo código, lectura dura.
- Los pipelines terminan en cualquier función:
|> printfncierra el circuito.
Palabras clave y builtins usados aquí
funlet
El intento, en números
- Líneas
- 14
- Caracteres a escribir
- 460
- Tokens
- 94
- Ritmo de tres estrellas
- 65 tpm
Al ritmo de tres estrellas de 65 tokens por minuto, este intento toma unos 87 segundos.
Paso 2 de 3 en Funciones; paso 5 de 27 en Fundamentos del lenguaje.