NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX

The mapPartial function

A common next step after mapping a function across a list is to filter out some unwanted results. These two steps can be combined in one by using the mapPartial function of type ('a -> 'b option) -> (('a list) -> ('b list)).

fun mapPartial f [] = []
  | mapPartial f (h::t) =
    case f h of
      NONE => mapPartial f t
    | SOME v => v :: mapPartial f t;

NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX