4 people like it.

Pipeline list processing

An example showing how to process list in a pipeline. We first use List.filter to return only even numbers and then use List.map to format them as strings.

Filtering and projection

1: 
2: 
3: 
4: 
let res = 
  [ 1 .. 10 ] 
  |> List.filter isEven
  |> List.map formatInt
val res : string list

Full name: Script.res
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val filter : predicate:('T -> bool) -> list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.filter
val isEven : n:int -> bool

Full name: Script.isEven
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val formatInt : n:int -> string

Full name: Script.formatInt

More information

Link:http://fssnip.net/u
Posted:7 months ago
Author:Tomas Petricek
Tags: pipeline , list , filter , map