Last active
November 22, 2016 18:03
-
-
Save neoeinstein/532fe7b155f3d97fc0fc2ed2f2f62c68 to your computer and use it in GitHub Desktop.
A decompiled version of the `Option` module fin FSharp.Core, along with the correlating IL. Produced with dotPeek 2016.2.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decompiled with JetBrains decompiler | |
// Type: Microsoft.FSharp.Core.OptionModule | |
// Assembly: FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | |
// MVID: 58348223-904C-F4DA-A745-038323823458 | |
// Assembly location: C:\dev\neoeinstein\visualfsharp\release\net40\bin\FSharp.Core.dll | |
// Compiler-generated code is shown | |
// IL code is shown in comments | |
using Microsoft.FSharp.Collections; | |
using System; | |
using System.Globalization; | |
namespace Microsoft.FSharp.Core | |
{ | |
// .class public abstract sealed auto ansi | |
// Microsoft.FSharp.Core.OptionModule | |
// extends [mscorlib]System.Object | |
// | |
/// <summary>Basic operations on options.</summary> | |
[CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)] | |
[CompilationMapping(SourceConstructFlags.Module)] | |
public static class OptionModule | |
{ | |
// .method public static !!0/*T*/ | |
// GetValue<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Gets the value associated with the option.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>The value within the option.</returns> | |
/// <exception href="System.ArgumentException">Thrown when the option is None.</exception> | |
[CompilationSourceName("get")] | |
public static T GetValue<T>(FSharpOption<T> option) | |
// .maxstack 5 | |
// .locals init ( | |
// [0] string V_0 | |
// ) | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_000b | |
// IL_0003: nop | |
// IL_0004: ldarg.0 // option | |
// IL_0005: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000a: ret | |
// IL_000b: call class [mscorlib]System.Resources.ResourceManager Microsoft.FSharp.Core.SR::get_resources() | |
// IL_0010: ldstr "optionValueWasNone" | |
// IL_0015: call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_CurrentUICulture() | |
// IL_001a: callvirt instance string [mscorlib]System.Resources.ResourceManager::GetString(string, class [mscorlib]System.Globalization.CultureInfo) | |
// IL_001f: stloc.0 // V_0 | |
// IL_0020: ldloc.0 // V_0 | |
// IL_0021: ldstr "option" | |
// IL_0026: newobj instance void [mscorlib]System.ArgumentException::.ctor(string, string) | |
// IL_002b: throw | |
// | |
{ | |
if (option != null) | |
return option.value; | |
throw new ArgumentException(SR.resources.GetString("optionValueWasNone", CultureInfo.CurrentUICulture), "option"); | |
} | |
// .method public static bool | |
// IsSome<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Returns true if the option is not None.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>True if the option is not None.</returns> | |
[CompilationSourceName("isSome")] | |
public static bool IsSome<T>(FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: nop | |
// IL_0001: ldarg.0 // option | |
// IL_0002: ldnull | |
// IL_0003: cgt.un | |
// IL_0005: ret | |
// | |
{ | |
return option != null; | |
} | |
// .method public static bool | |
// IsNone<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Returns true if the option is None.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>True if the option is None.</returns> | |
[CompilationSourceName("isNone")] | |
public static bool IsNone<T>(FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: nop | |
// IL_0001: ldarg.0 // option | |
// IL_0002: ldnull | |
// IL_0003: cgt.un | |
// IL_0005: ldc.i4.0 | |
// IL_0006: ceq | |
// IL_0008: ret | |
// | |
{ | |
return option == null; | |
} | |
// .method public static !!0/*T*/ | |
// DefaultValue<T>( | |
// !!0/*T*/ 'value', | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Gets the value of the option if the option is <c>Some</c>, otherwise returns the specified default value.</summary> | |
/// <param name="value">The specified default value.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The option if the option is Some, else the default value.</returns> | |
/// <remarks>Identical to the built-in <see cref="defaultArg" /> operator, except with the arguments swapped.</remarks> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("defaultValue")] | |
public static T DefaultValue<T>(T value, FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_000b | |
// IL_0003: nop | |
// IL_0004: ldarg.1 // option | |
// IL_0005: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000a: ret | |
// IL_000b: ldarg.0 // 'value' | |
// IL_000c: ret | |
// | |
{ | |
if (option != null) | |
return option.value; | |
return value; | |
} | |
// .method public static !!0/*T*/ | |
// DefaultWith<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Core.Unit, !!0/*T*/> defThunk, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Gets the value of the option if the option is <c>Some</c>, otherwise evaluates <paramref name="defThunk" /> and returns the result.</summary> | |
/// <param name="defThunk">A thunk that provides a default value when evaluated.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The option if the option is Some, else the result of evaluating <paramref name="defThunk" />.</returns> | |
/// <remarks><paramref name="defThunk" /> is not evaluated unless <paramref name="option" /> is <c>None</c>.</remarks> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("defaultWith")] | |
public static T DefaultWith<T>(FSharpFunc<Unit, T> defThunk, FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_000b | |
// IL_0003: nop | |
// IL_0004: ldarg.1 // option | |
// IL_0005: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000a: ret | |
// IL_000b: ldarg.0 // defThunk | |
// IL_000c: ldnull | |
// IL_000d: tail. | |
// IL_000f: callvirt instance !1/*T*/ class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Core.Unit, !!0/*T*/>::Invoke(!0/*class Microsoft.FSharp.Core.Unit*/) | |
// IL_0014: ret | |
// | |
{ | |
if (option != null) | |
return option.value; | |
return defThunk.Invoke((Unit) null); | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// OrElse<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> ifNone, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Returns <paramref name="option" /> if it is <c>Some</c>, otherwise returns <paramref name="ifNone" />.</summary> | |
/// <param name="ifNone">The value to use if <paramref name="option" /> is <c>None</c>.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The option if the option is Some, else the alternate option.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("orElse")] | |
public static FSharpOption<T> OrElse<T>(FSharpOption<T> ifNone, FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0006 | |
// IL_0003: nop | |
// IL_0004: ldarg.1 // option | |
// IL_0005: ret | |
// IL_0006: ldarg.0 // ifNone | |
// IL_0007: ret | |
// | |
{ | |
if (option != null) | |
return option; | |
return ifNone; | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// OrElseWith<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Core.Unit, class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>> ifNoneThunk, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Returns <paramref name="option" /> if it is <c>Some</c>, otherwise evaluates <paramref name="ifNoneThunk" /> and returns the result.</summary> | |
/// <param name="ifNoneThunk">A thunk that provides an alternate option when evaluated.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The option if the option is Some, else the result of evaluating <paramref name="ifNoneThunk" />.</returns> | |
/// <remarks><paramref name="ifNoneThunk" /> is not evaluated unless <paramref name="option" /> is <c>None</c>.</remarks> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("orElseWith")] | |
public static FSharpOption<T> OrElseWith<T>(FSharpFunc<Unit, FSharpOption<T>> ifNoneThunk, FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0006 | |
// IL_0003: nop | |
// IL_0004: ldarg.1 // option | |
// IL_0005: ret | |
// IL_0006: ldarg.0 // ifNoneThunk | |
// IL_0007: ldnull | |
// IL_0008: tail. | |
// IL_000a: callvirt instance !1/*class Microsoft.FSharp.Core.FSharpOption`1<T>*/ class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Core.Unit, class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>>::Invoke(!0/*class Microsoft.FSharp.Core.Unit*/) | |
// IL_000f: ret | |
// | |
{ | |
if (option != null) | |
return option; | |
return ifNoneThunk.Invoke((Unit) null); | |
} | |
// .method public static int32 | |
// Count<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>count inp</c> evaluates to <c>match inp with None -> 0 | Some _ -> 1</c>.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>A zero if the option is None, a one otherwise.</returns> | |
[CompilationSourceName("count")] | |
public static int Count<T>(FSharpOption<T> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_0006 | |
// IL_0003: nop | |
// IL_0004: ldc.i4.1 | |
// IL_0005: ret | |
// IL_0006: ldc.i4.0 | |
// IL_0007: ret | |
// | |
{ | |
return option != null ? 1 : 0; | |
} | |
// .method public static !!1/*TState*/ | |
// Fold<T, TState>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!1/*TState*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, !!1/*TState*/>> folder, | |
// !!1/*TState*/ state, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>fold f s inp</c> evaluates to <c>match inp with None -> s | Some x -> f s x</c>.</summary> | |
/// <param name="folder">A function to update the state data when given a value from an option.</param> | |
/// <param name="state">The initial state.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The original state if the option is None, otherwise it returns the updated state with the folder | |
/// and the option value.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1, 1})] | |
[CompilationSourceName("fold")] | |
public static TState Fold<T, TState>(FSharpFunc<TState, FSharpFunc<T, TState>> folder, TState state, FSharpOption<T> option) | |
// .maxstack 5 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0008 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.2 // option | |
// IL_0001: brfalse.s IL_0016 | |
// IL_0003: ldarg.2 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0008 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // folder | |
// IL_0007: ldarg.1 // state | |
// IL_0008: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0008 ldloc.0))]' | |
// IL_0009: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000e: tail. | |
// IL_0010: call !!0/*TState*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!1/*TState*/, !!0/*T*/>::InvokeFast<!!1/*TState*/>(class Microsoft.FSharp.Core.FSharpFunc`2<!0/*TState*/, class Microsoft.FSharp.Core.FSharpFunc`2<!1/*T*/, !!0/*TState*/>>, !0/*TState*/, !1/*T*/) | |
// IL_0015: ret | |
// IL_0016: ldarg.1 // state | |
// IL_0017: ret | |
// | |
{ | |
if (option == null) | |
return state; | |
FSharpOption<T> fsharpOption = option; | |
return FSharpFunc<TState, T>.InvokeFast<TState>(folder, state, fsharpOption.value); | |
} | |
// .method public static !!1/*TState*/ | |
// FoldBack<T, TState>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!1/*TState*/, !!1/*TState*/>> folder, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option, | |
// !!1/*TState*/ state | |
// ) cil managed | |
/// <summary><c>fold f inp s</c> evaluates to <c>match inp with None -> s | Some x -> f x s</c>.</summary> | |
/// <param name="folder">A function to update the state data when given a value from an option.</param> | |
/// <param name="option">The input option.</param> | |
/// <param name="state">The initial state.</param> | |
/// <returns>The original state if the option is None, otherwise it returns the updated state with the folder | |
/// and the option value.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1, 1})] | |
[CompilationSourceName("foldBack")] | |
public static TState FoldBack<T, TState>(FSharpFunc<T, FSharpFunc<TState, TState>> folder, FSharpOption<T> option, TState state) | |
// .maxstack 5 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0016 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // folder | |
// IL_0007: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0008: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000d: ldarg.2 // state | |
// IL_000e: tail. | |
// IL_0010: call !!0/*TState*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, !!1/*TState*/>::InvokeFast<!!1/*TState*/>(class Microsoft.FSharp.Core.FSharpFunc`2<!0/*T*/, class Microsoft.FSharp.Core.FSharpFunc`2<!1/*TState*/, !!0/*TState*/>>, !0/*T*/, !1/*TState*/) | |
// IL_0015: ret | |
// IL_0016: ldarg.2 // state | |
// IL_0017: ret | |
// | |
{ | |
if (option == null) | |
return state; | |
FSharpOption<T> fsharpOption = option; | |
return FSharpFunc<T, TState>.InvokeFast<TState>(folder, fsharpOption.value, state); | |
} | |
// .method public static bool | |
// Exists<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool> predicate, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>exists p inp</c> evaluates to <c>match inp with None -> false | Some x -> p x</c>.</summary> | |
/// <param name="predicate">A function that evaluates to a boolean when given a value from the option type.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>False if the option is None, otherwise it returns the result of applying the predicate | |
/// to the option value.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("exists")] | |
public static bool Exists<T>(FSharpFunc<T, bool> predicate, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0015 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // predicate | |
// IL_0007: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0008: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000d: tail. | |
// IL_000f: callvirt instance !1/*bool*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool>::Invoke(!0/*T*/) | |
// IL_0014: ret | |
// IL_0015: ldc.i4.0 | |
// IL_0016: ret | |
// | |
{ | |
if (option == null) | |
return false; | |
FSharpOption<T> fsharpOption = option; | |
return predicate.Invoke(fsharpOption.value); | |
} | |
// .method public static bool | |
// ForAll<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool> predicate, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>forall p inp</c> evaluates to <c>match inp with None -> true | Some x -> p x</c>.</summary> | |
/// <param name="predicate">A function that evaluates to a boolean when given a value from the option type.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>True if the option is None, otherwise it returns the result of applying the predicate | |
/// to the option value.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("forall")] | |
public static bool ForAll<T>(FSharpFunc<T, bool> predicate, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0015 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // predicate | |
// IL_0007: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0008: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000d: tail. | |
// IL_000f: callvirt instance !1/*bool*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool>::Invoke(!0/*T*/) | |
// IL_0014: ret | |
// IL_0015: ldc.i4.1 | |
// IL_0016: ret | |
// | |
{ | |
if (option == null) | |
return true; | |
FSharpOption<T> fsharpOption = option; | |
return predicate.Invoke(fsharpOption.value); | |
} | |
// .method public static bool | |
// Contains<T>( | |
// !!0/*T*/ 'value', | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Evaluates to true if <paramref name="option" /> is <c>Some</c> and its value is equal to <paramref name="value" />.</summary> | |
/// <param name="value">The value to test for equality.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>True if the option is <c>Some</c> and contains a value equal to <paramref name="value" />, otherwise false.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("contains")] | |
public static bool Contains<T>(T value, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0, | |
// [1] !!0/*T*/ V_1 | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0017 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: ldloc.0 // V_0 | |
// IL_0006: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000b: stloc.1 // V_1 | |
// IL_000c: nop | |
// IL_000d: ldloc.1 // V_1 | |
// IL_000e: ldarg.0 // 'value' | |
// IL_000f: tail. | |
// IL_0011: call bool Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic<!!0/*T*/>(!!0/*T*/, !!0/*T*/) | |
// IL_0016: ret | |
// IL_0017: ldc.i4.0 | |
// IL_0018: ret | |
// | |
{ | |
if (option != null) | |
return LanguagePrimitives.HashCompare.GenericEqualityIntrinsic<T>(option.value, value); | |
return false; | |
} | |
// .method public static void | |
// Iterate<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, class Microsoft.FSharp.Core.Unit> action, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>iter f inp</c> executes <c>match inp with None -> () | Some x -> f x</c>.</summary> | |
/// <param name="action">A function to apply to the option value.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>Unit if the option is None, otherwise it returns the result of applying the predicate | |
/// to the option value.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("iter")] | |
public static void Iterate<T>(FSharpFunc<T, Unit> action, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0014 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // action | |
// IL_0007: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0008: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000d: callvirt instance !1/*class Microsoft.FSharp.Core.Unit*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, class Microsoft.FSharp.Core.Unit>::Invoke(!0/*T*/) | |
// IL_0012: pop | |
// IL_0013: ret | |
// IL_0014: ret | |
// | |
{ | |
if (option == null) | |
return; | |
FSharpOption<T> fsharpOption = option; | |
action.Invoke(fsharpOption.value); | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!1/*TResult*/> | |
// Map<T, TResult>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, !!1/*TResult*/> mapping, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>map f inp</c> evaluates to <c>match inp with None -> None | Some x -> Some (f x)</c>.</summary> | |
/// <param name="mapping">A function to apply to the option value.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>An option of the input value after applying the mapping function, or None if the input is None.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("map")] | |
public static FSharpOption<TResult> Map<T, TResult>(FSharpFunc<T, TResult> mapping, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0, | |
// [1] !!0/*T*/ 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_000e ldloc.1))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_001a | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: ldloc.0 // V_0 | |
// IL_0006: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000b: stloc.1 // 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_000e ldloc.1))]' | |
// IL_000c: nop | |
// IL_000d: ldarg.0 // mapping | |
// IL_000e: ldloc.1 // 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_000e ldloc.1))]' | |
// IL_000f: callvirt instance !1/*TResult*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, !!1/*TResult*/>::Invoke(!0/*T*/) | |
// IL_0014: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*TResult*/> class Microsoft.FSharp.Core.FSharpOption`1<!!1/*TResult*/>::Some(!0/*TResult*/) | |
// IL_0019: ret | |
// IL_001a: ldnull | |
// IL_001b: ret | |
// | |
{ | |
if (option == null) | |
return (FSharpOption<TResult>) null; | |
T func = option.value; | |
return FSharpOption<TResult>.Some(mapping.Invoke(func)); | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!2/*TResult*/> | |
// Map2<T1, T2, TResult>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T1*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!1/*T2*/, !!2/*TResult*/>> mapping, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/> option1, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/> option2 | |
// ) cil managed | |
/// <summary><c>map f option1 option2</c> evaluates to <c>match option1, option2 with Some x, Some y -> Some (f x y) | _ -> None</c>.</summary> | |
/// <param name="mapping">A function to apply to the option values.</param> | |
/// <param name="option1">The first option.</param> | |
/// <param name="option2">The second option.</param> | |
/// <returns>An option of the input values after applying the mapping function, or None if either input is None.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1, 1})] | |
[CompilationSourceName("map2")] | |
public static FSharpOption<TResult> Map2<T1, T2, TResult>(FSharpFunc<T1, FSharpFunc<T2, TResult>> mapping, FSharpOption<T1> option1, FSharpOption<T2> option2) | |
// .maxstack 5 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0011 ldloc.0))]', | |
// [1] class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/> V_1, | |
// [2] !!1/*T2*/ 'obj1 [Range(Instruction(IL_0010 stloc.2)-Instruction(IL_001b ldloc.2))]', | |
// [3] !!0/*T1*/ 'obj2 [Range(Instruction(IL_0017 stloc.3)-Instruction(IL_001a ldloc.3))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option1 | |
// IL_0001: brfalse.s IL_0027 | |
// IL_0003: ldarg.1 // option1 | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0011 ldloc.0))]' | |
// IL_0005: ldarg.2 // option2 | |
// IL_0006: brfalse.s IL_0027 | |
// IL_0008: ldarg.2 // option2 | |
// IL_0009: stloc.1 // V_1 | |
// IL_000a: ldloc.1 // V_1 | |
// IL_000b: ldfld !0/*T2*/ class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/>::'value' | |
// IL_0010: stloc.2 // 'obj1 [Range(Instruction(IL_0010 stloc.2)-Instruction(IL_001b ldloc.2))]' | |
// IL_0011: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0011 ldloc.0))]' | |
// IL_0012: ldfld !0/*T1*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/>::'value' | |
// IL_0017: stloc.3 // 'obj2 [Range(Instruction(IL_0017 stloc.3)-Instruction(IL_001a ldloc.3))]' | |
// IL_0018: nop | |
// IL_0019: ldarg.0 // mapping | |
// IL_001a: ldloc.3 // 'obj2 [Range(Instruction(IL_0017 stloc.3)-Instruction(IL_001a ldloc.3))]' | |
// IL_001b: ldloc.2 // 'obj1 [Range(Instruction(IL_0010 stloc.2)-Instruction(IL_001b ldloc.2))]' | |
// IL_001c: call !!0/*TResult*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T1*/, !!1/*T2*/>::InvokeFast<!!2/*TResult*/>(class Microsoft.FSharp.Core.FSharpFunc`2<!0/*T1*/, class Microsoft.FSharp.Core.FSharpFunc`2<!1/*T2*/, !!0/*TResult*/>>, !0/*T1*/, !1/*T2*/) | |
// IL_0021: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*TResult*/> class Microsoft.FSharp.Core.FSharpOption`1<!!2/*TResult*/>::Some(!0/*TResult*/) | |
// IL_0026: ret | |
// IL_0027: ldnull | |
// IL_0028: ret | |
// | |
{ | |
if (option1 != null) | |
{ | |
FSharpOption<T1> fsharpOption = option1; | |
if (option2 != null) | |
{ | |
T2 obj1 = option2.value; | |
T1 obj2 = fsharpOption.value; | |
return FSharpOption<TResult>.Some(FSharpFunc<T1, T2>.InvokeFast<TResult>(mapping, obj2, obj1)); | |
} | |
} | |
return (FSharpOption<TResult>) null; | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!3/*TResult*/> | |
// Map3<T1, T2, T3, TResult>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T1*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!1/*T2*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!2/*T3*/, !!3/*TResult*/>>> mapping, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/> option1, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/> option2, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!2/*T3*/> option3 | |
// ) cil managed | |
/// <summary><c>map f option1 option2 option3</c> evaluates to <c>match option1, option2, option3 with Some x, Some y, Some z -> Some (f x y z) | _ -> None</c>.</summary> | |
/// <param name="mapping">A function to apply to the option values.</param> | |
/// <param name="option1">The first option.</param> | |
/// <param name="option2">The second option.</param> | |
/// <param name="option3">The third option.</param> | |
/// <returns>An option of the input values after applying the mapping function, or None if any input is None.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1, 1, 1})] | |
[CompilationSourceName("map3")] | |
public static FSharpOption<TResult> Map3<T1, T2, T3, TResult>(FSharpFunc<T1, FSharpFunc<T2, FSharpFunc<T3, TResult>>> mapping, FSharpOption<T1> option1, FSharpOption<T2> option2, FSharpOption<T3> option3) | |
// .maxstack 6 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/> 'fsharpOption1 [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_001e ldloc.0))]', | |
// [1] class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/> 'fsharpOption2 [Range(Instruction(IL_0009 stloc.1)-Instruction(IL_0016 ldloc.1))]', | |
// [2] class Microsoft.FSharp.Core.FSharpOption`1<!!2/*T3*/> V_2, | |
// [3] !!2/*T3*/ 'obj1 [Range(Instruction(IL_0015 stloc.3)-Instruction(IL_002c ldloc.3))]', | |
// [4] !!1/*T2*/ 'obj2 [Range(Instruction(IL_001c stloc.s)-Instruction(IL_002a ldloc.s))]', | |
// [5] !!0/*T1*/ 'obj3 [Range(Instruction(IL_0024 stloc.s)-Instruction(IL_0028 ldloc.s))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option1 | |
// IL_0001: brfalse.s IL_0038 | |
// IL_0003: ldarg.1 // option1 | |
// IL_0004: stloc.0 // 'fsharpOption1 [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_001e ldloc.0))]' | |
// IL_0005: ldarg.2 // option2 | |
// IL_0006: brfalse.s IL_0038 | |
// IL_0008: ldarg.2 // option2 | |
// IL_0009: stloc.1 // 'fsharpOption2 [Range(Instruction(IL_0009 stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// IL_000a: ldarg.3 // option3 | |
// IL_000b: brfalse.s IL_0038 | |
// IL_000d: ldarg.3 // option3 | |
// IL_000e: stloc.2 // V_2 | |
// IL_000f: ldloc.2 // V_2 | |
// IL_0010: ldfld !0/*T3*/ class Microsoft.FSharp.Core.FSharpOption`1<!!2/*T3*/>::'value' | |
// IL_0015: stloc.3 // 'obj1 [Range(Instruction(IL_0015 stloc.3)-Instruction(IL_002c ldloc.3))]' | |
// IL_0016: ldloc.1 // 'fsharpOption2 [Range(Instruction(IL_0009 stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// IL_0017: ldfld !0/*T2*/ class Microsoft.FSharp.Core.FSharpOption`1<!!1/*T2*/>::'value' | |
// IL_001c: stloc.s 'obj2 [Range(Instruction(IL_001c stloc.s)-Instruction(IL_002a ldloc.s))]' | |
// IL_001e: ldloc.0 // 'fsharpOption1 [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_001e ldloc.0))]' | |
// IL_001f: ldfld !0/*T1*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T1*/>::'value' | |
// IL_0024: stloc.s 'obj3 [Range(Instruction(IL_0024 stloc.s)-Instruction(IL_0028 ldloc.s))]' | |
// IL_0026: nop | |
// IL_0027: ldarg.0 // mapping | |
// IL_0028: ldloc.s 'obj3 [Range(Instruction(IL_0024 stloc.s)-Instruction(IL_0028 ldloc.s))]' | |
// IL_002a: ldloc.s 'obj2 [Range(Instruction(IL_001c stloc.s)-Instruction(IL_002a ldloc.s))]' | |
// IL_002c: ldloc.3 // 'obj1 [Range(Instruction(IL_0015 stloc.3)-Instruction(IL_002c ldloc.3))]' | |
// IL_002d: call !!1/*TResult*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T1*/, !!1/*T2*/>::InvokeFast<!!2/*T3*/, !!3/*TResult*/>(class Microsoft.FSharp.Core.FSharpFunc`2<!0/*T1*/, class Microsoft.FSharp.Core.FSharpFunc`2<!1/*T2*/, class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T3*/, !!1/*TResult*/>>>, !0/*T1*/, !1/*T2*/, !!0/*T3*/) | |
// IL_0032: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*TResult*/> class Microsoft.FSharp.Core.FSharpOption`1<!!3/*TResult*/>::Some(!0/*TResult*/) | |
// IL_0037: ret | |
// IL_0038: ldnull | |
// IL_0039: ret | |
// | |
{ | |
if (option1 != null) | |
{ | |
FSharpOption<T1> fsharpOption1 = option1; | |
if (option2 != null) | |
{ | |
FSharpOption<T2> fsharpOption2 = option2; | |
if (option3 != null) | |
{ | |
T3 obj1 = option3.value; | |
T2 obj2 = fsharpOption2.value; | |
T1 obj3 = fsharpOption1.value; | |
return FSharpOption<TResult>.Some(FSharpFunc<T1, T2>.InvokeFast<T3, TResult>(mapping, obj3, obj2, obj1)); | |
} | |
} | |
} | |
return (FSharpOption<TResult>) null; | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!1/*TResult*/> | |
// Bind<T, TResult>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, class Microsoft.FSharp.Core.FSharpOption`1<!!1/*TResult*/>> binder, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>bind f inp</c> evaluates to <c>match inp with None -> None | Some x -> f x</c></summary> | |
/// <param name="binder">A function that takes the value of type T from an option and transforms it into | |
/// an option containing a value of type U.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>An option of the output type of the binder.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("bind")] | |
public static FSharpOption<TResult> Bind<T, TResult>(FSharpFunc<T, FSharpOption<TResult>> binder, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_0015 | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0005: nop | |
// IL_0006: ldarg.0 // binder | |
// IL_0007: ldloc.0 // 'fsharpOption [Range(Instruction(IL_0004 stloc.0)-Instruction(IL_0007 ldloc.0))]' | |
// IL_0008: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000d: tail. | |
// IL_000f: callvirt instance !1/*class Microsoft.FSharp.Core.FSharpOption`1<TResult>*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, class Microsoft.FSharp.Core.FSharpOption`1<!!1/*TResult*/>>::Invoke(!0/*T*/) | |
// IL_0014: ret | |
// IL_0015: ldnull | |
// IL_0016: ret | |
// | |
{ | |
if (option == null) | |
return (FSharpOption<TResult>) null; | |
FSharpOption<T> fsharpOption = option; | |
return binder.Invoke(fsharpOption.value); | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// Flatten<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>> option | |
// ) cil managed | |
/// <summary><c>flatten inp</c> evaluates to <c>match inp with None -> None | Some x -> x</c></summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>An option of the output type of the binder.</returns> | |
/// <remarks><c>flatten</c> is equivalent to <c>bind id</c>.</remarks> | |
[CompilationSourceName("flatten")] | |
public static FSharpOption<T> Flatten<T>(FSharpOption<FSharpOption<T>> option) | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_000b | |
// IL_0003: nop | |
// IL_0004: ldarg.0 // option | |
// IL_0005: ldfld !0/*class Microsoft.FSharp.Core.FSharpOption`1<T>*/ class Microsoft.FSharp.Core.FSharpOption`1<class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>>::'value' | |
// IL_000a: ret | |
// IL_000b: ldnull | |
// IL_000c: ret | |
// | |
{ | |
if (option != null) | |
return option.value; | |
return (FSharpOption<T>) null; | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// Filter<T>( | |
// class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool> predicate, | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary><c>filter f inp</c> evaluates to <c>match inp with None -> None | Some x -> if f x then Some x else None</c>.</summary> | |
/// <param name="predicate">A function that evaluates whether the value contained in the option should remain, or be filtered out.</param> | |
/// <param name="option">The input option.</param> | |
/// <returns>The input if the predicate evaluates to true; otherwise, None.</returns> | |
[CompilationArgumentCounts(new int[] {1, 1})] | |
[CompilationSourceName("filter")] | |
public static FSharpOption<T> Filter<T>(FSharpFunc<T, bool> predicate, FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0, | |
// [1] !!0/*T*/ 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// ) | |
// | |
// IL_0000: ldarg.1 // option | |
// IL_0001: brfalse.s IL_001f | |
// IL_0003: ldarg.1 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: ldloc.0 // V_0 | |
// IL_0006: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000b: stloc.1 // 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// IL_000c: nop | |
// IL_000d: ldarg.0 // predicate | |
// IL_000e: ldloc.1 // 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// IL_000f: callvirt instance !1/*bool*/ class Microsoft.FSharp.Core.FSharpFunc`2<!!0/*T*/, bool>::Invoke(!0/*T*/) | |
// IL_0014: brfalse.s IL_001d | |
// IL_0016: ldloc.1 // 'func [Range(Instruction(IL_000b stloc.1)-Instruction(IL_0016 ldloc.1))]' | |
// IL_0017: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*T*/> class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::Some(!0/*T*/) | |
// IL_001c: ret | |
// IL_001d: ldnull | |
// IL_001e: ret | |
// IL_001f: ldnull | |
// IL_0020: ret | |
// | |
{ | |
if (option == null) | |
return (FSharpOption<T>) null; | |
T func = option.value; | |
if (predicate.Invoke(func)) | |
return FSharpOption<T>.Some(func); | |
return (FSharpOption<T>) null; | |
} | |
// .method public static !!0/*T*/[] | |
// ToArray<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Convert the option to an array of length 0 or 1.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>The result array.</returns> | |
[CompilationSourceName("toArray")] | |
public static T[] ToArray<T>(FSharpOption<T> option) | |
// .maxstack 6 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0 | |
// ) | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_001a | |
// IL_0003: ldarg.0 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: nop | |
// IL_0006: ldc.i4.1 | |
// IL_0007: newarr !!0/*T*/ | |
// IL_000c: dup | |
// IL_000d: ldc.i4.0 | |
// IL_000e: ldloc.0 // V_0 | |
// IL_000f: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_0014: stelem !!0/*T*/ | |
// IL_0019: ret | |
// IL_001a: ldc.i4.0 | |
// IL_001b: newarr !!0/*T*/ | |
// IL_0020: ret | |
// | |
{ | |
if (option == null) | |
return new T[0]; | |
return new T[1]{ option.value }; | |
} | |
// .method public static class Microsoft.FSharp.Collections.FSharpList`1<!!0/*T*/> | |
// ToList<T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Convert the option to a list of length 0 or 1.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>The result list.</returns> | |
[CompilationSourceName("toList")] | |
public static FSharpList<T> ToList<T>(FSharpOption<T> option) | |
// .maxstack 4 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0 | |
// ) | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_0017 | |
// IL_0003: ldarg.0 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: nop | |
// IL_0006: ldloc.0 // V_0 | |
// IL_0007: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000c: call class Microsoft.FSharp.Collections.FSharpList`1<!0/*T*/> class Microsoft.FSharp.Collections.FSharpList`1<!!0/*T*/>::get_Empty() | |
// IL_0011: call class Microsoft.FSharp.Collections.FSharpList`1<!0/*T*/> class Microsoft.FSharp.Collections.FSharpList`1<!!0/*T*/>::Cons(!0/*T*/, class Microsoft.FSharp.Collections.FSharpList`1<!0/*T*/>) | |
// IL_0016: ret | |
// IL_0017: call class Microsoft.FSharp.Collections.FSharpList`1<!0/*T*/> class Microsoft.FSharp.Collections.FSharpList`1<!!0/*T*/>::get_Empty() | |
// IL_001c: ret | |
// | |
{ | |
if (option != null) | |
return FSharpList<T>.Cons(option.value, FSharpList<T>.get_Empty()); | |
return FSharpList<T>.get_Empty(); | |
} | |
// .method public static valuetype [mscorlib]System.Nullable`1<!!0/*T*/> | |
// ToNullable<valuetype .ctor (class [mscorlib]System.ValueType) T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> option | |
// ) cil managed | |
/// <summary>Convert the option to a Nullable value.</summary> | |
/// <param name="option">The input option.</param> | |
/// <returns>The result value.</returns> | |
[CompilationSourceName("toNullable")] | |
public static T? ToNullable<T>(FSharpOption<T> option) where T : struct | |
// .maxstack 3 | |
// .locals init ( | |
// [0] class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> V_0, | |
// [1] valuetype [mscorlib]System.Nullable`1<!!0/*T*/> V_1 | |
// ) | |
// | |
// IL_0000: ldarg.0 // option | |
// IL_0001: brfalse.s IL_0012 | |
// IL_0003: ldarg.0 // option | |
// IL_0004: stloc.0 // V_0 | |
// IL_0005: nop | |
// IL_0006: ldloc.0 // V_0 | |
// IL_0007: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000c: newobj instance void valuetype [mscorlib]System.Nullable`1<!!0/*T*/>::.ctor(!0/*T*/) | |
// IL_0011: ret | |
// IL_0012: ldloca.s V_1 | |
// IL_0014: initobj valuetype [mscorlib]System.Nullable`1<!!0/*T*/> | |
// IL_001a: ldloc.1 // V_1 | |
// IL_001b: ret | |
// | |
{ | |
if (option != null) | |
return new T?(option.value); | |
return new T?(); | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// OfNullable<valuetype .ctor (class [mscorlib]System.ValueType) T>( | |
// valuetype [mscorlib]System.Nullable`1<!!0/*T*/> 'value' | |
// ) cil managed | |
/// <summary>Convert a Nullable value to an option.</summary> | |
/// <param name="value">The input nullable value.</param> | |
/// <returns>The result option.</returns> | |
[CompilationSourceName("ofNullable")] | |
public static FSharpOption<T> OfNullable<T>(T? value) where T : struct | |
// .maxstack 8 | |
// | |
// IL_0000: nop | |
// IL_0001: ldarga.s 'value' | |
// IL_0003: call instance bool valuetype [mscorlib]System.Nullable`1<!!0/*T*/>::get_HasValue() | |
// IL_0008: brfalse.s IL_0017 | |
// IL_000a: ldarga.s 'value' | |
// IL_000c: call instance !0/*T*/ valuetype [mscorlib]System.Nullable`1<!!0/*T*/>::get_Value() | |
// IL_0011: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*T*/> class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::Some(!0/*T*/) | |
// IL_0016: ret | |
// IL_0017: ldnull | |
// IL_0018: ret | |
// | |
{ | |
if (value.HasValue) | |
return FSharpOption<T>.Some(value.Value); | |
return (FSharpOption<T>) null; | |
} | |
// .method public static class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> | |
// OfObj<class T>( | |
// !!0/*T*/ 'value' | |
// ) cil managed | |
/// <summary>Convert a potentially null value to an option.</summary> | |
/// <param name="value">The input value.</param> | |
/// <returns>The result option.</returns> | |
[CompilationSourceName("ofObj")] | |
public static FSharpOption<T> OfObj<T>(T value) where T : class | |
// .maxstack 8 | |
// | |
// IL_0000: ldarg.0 // 'value' | |
// IL_0001: box !!0/*T*/ | |
// IL_0006: brfalse.s IL_0010 | |
// IL_0008: nop | |
// IL_0009: ldarg.0 // 'value' | |
// IL_000a: call class Microsoft.FSharp.Core.FSharpOption`1<!0/*T*/> class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::Some(!0/*T*/) | |
// IL_000f: ret | |
// IL_0010: ldnull | |
// IL_0011: ret | |
// | |
{ | |
if ((object) value != null) | |
return FSharpOption<T>.Some(value); | |
return (FSharpOption<T>) null; | |
} | |
// .method public static !!0/*T*/ | |
// ToObj<class T>( | |
// class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/> 'value' | |
// ) cil managed | |
/// <summary>Convert an option to a potentially null value.</summary> | |
/// <param name="value">The input value.</param> | |
/// <returns>The result value, which is null if the input was None.</returns> | |
[CompilationSourceName("toObj")] | |
public static T ToObj<T>(FSharpOption<T> value) where T : class | |
// .maxstack 3 | |
// .locals init ( | |
// [0] !!0/*T*/ V_0 | |
// ) | |
// | |
// IL_0000: ldarg.0 // 'value' | |
// IL_0001: brfalse.s IL_000b | |
// IL_0003: nop | |
// IL_0004: ldarg.0 // 'value' | |
// IL_0005: ldfld !0/*T*/ class Microsoft.FSharp.Core.FSharpOption`1<!!0/*T*/>::'value' | |
// IL_000a: ret | |
// IL_000b: ldloca.s V_0 | |
// IL_000d: initobj !!0/*T*/ | |
// IL_0013: ldloc.0 // V_0 | |
// IL_0014: ret | |
// | |
{ | |
if (value != null) | |
return value.value; | |
return default (T); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment