option
本頁內容尚未翻譯。
Option.filter
Section titled “Option.filter”def filter {A : Type} (test : A -> Bool) (o : Option A) : Option AThe value, if it passes the test.
Option.join
Section titled “Option.join”def join {A : Type} (o : Option (Option A)) : Option AA nested option flattened.
Option.zipWith
Section titled “Option.zipWith”def zipWith {A : Type} {B : Type} {C : Type} (f : A -> B -> C) (oa : Option A) (ob : Option B) : Option Cf of both values when both are present.
Option.zip
Section titled “Option.zip”def zip {A : Type} {B : Type} (oa : Option A) (ob : Option B) : Option (A * B)Both values as a pair, when both are present.
Option.apply
Section titled “Option.apply”def apply {A : Type} {B : Type} (of : Option (A -> B)) (oa : Option A) : Option BA present function applied to a present value.
Option.fold
Section titled “Option.fold”def fold {A : Type} {B : Type} (absent : B) (f : A -> B) (o : Option A) : Bf of the value, or absent when there is none.
Option.any
Section titled “Option.any”def any {A : Type} (test : A -> Bool) (o : Option A) : BoolWhether there is a value and it passes the test.
Option.all
Section titled “Option.all”def all {A : Type} (test : A -> Bool) (o : Option A) : BoolWhether every value (none, or the one there is) passes the test.
Option.when
Section titled “Option.when”def when {A : Type} (condition : Bool) (a : A) : Option Asome a when the condition holds, else none.
Option.mapIdentity
Section titled “Option.mapIdentity”def mapIdentity {A : Type} (o : Option A) : Option.map (fun (a : A) => a) o = oMapping the identity changes nothing.
Option.mapCompose
Section titled “Option.mapCompose”def mapCompose {A : Type} {B : Type} {C : Type} (f : A -> B) (g : B -> C) (o : Option A) : Option.map g (Option.map f o) = Option.map (fun (a : A) => g (f a)) oMapping twice is mapping the composition.
Option.bindSome
Section titled “Option.bindSome”def bindSome {A : Type} {B : Type} (a : A) (f : A -> Option B) : Option.bind (some a) f = f aChaining a present value into f is f of it.
Option.bindIntoSome
Section titled “Option.bindIntoSome”def bindIntoSome {A : Type} (o : Option A) : Option.bind o (fun (a : A) => some a) = oChaining into some changes nothing.
Option.bindAssociative
Section titled “Option.bindAssociative”def bindAssociative {A : Type} {B : Type} {C : Type} (o : Option A) (f : A -> Option B) (g : B -> Option C) : Option.bind (Option.bind o f) g = Option.bind o (fun (a : A) => Option.bind (f a) g)Chaining is associative.
Option.joinIsBind
Section titled “Option.joinIsBind”def joinIsBind {A : Type} (o : Option (Option A)) : join o = Option.bind o (fun (inner : Option A) => inner)Flattening is chaining into the inner option.
Option.orElseAssociative
Section titled “Option.orElseAssociative”def orElseAssociative {A : Type} (a : Option A) (b : Option A) (c : Option A) : Option.orElse (Option.orElse a b) c = Option.orElse a (Option.orElse b c)Taking the first present option is associative.
Option.withDefaultIsFold
Section titled “Option.withDefaultIsFold”def withDefaultIsFold {A : Type} (d : A) (o : Option A) : Option.withDefault d o = fold d (fun (a : A) => a) oThe value or a default is a fold.