Getting started with Fungible
Let's start with the core functionality by loading the basic references and opening the appropriate namespaces. Barb is an optional dependency, but we'll be using it in later examples.
1: 2: 3: 4: 5: 6: |
|
Next we need to define a record tree structure to operate on.
1: 2: 3: 4: 5: 6: |
|
As well as a sample to play around with. In this case we are only using one record sample for clarity, but Fungible was desinged to be used with record counts in the hundreds of thousands to millions.
1: 2: 3: 4: 5: 6: 7: 8: |
|
For a simple starting example we will just transform the City field within the Locations member of person to be uppercase. When the type is None no action will be taken, when it's Some the transform will be applied.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: |
|
But what if you want to uppercase many different fields? Just add a path for each place you want to change with the corresponding function.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
What if we want to apply multiple different transforms to the same field? Just list the transforms and they'll be executed in order.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
Let's dig into the static reflection part of the library, which is used for pulling functions in from F# libraries based on a settings spec.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: |
|
Next let's explore using Barb functions with the Barb extension library.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
You can mix Barb and Static Reflection transforms interchangeably.
1: 2: 3: 4: |
|
from Fungible
{Day: byte;
Month: byte;
Year: uint16;}
Full name: Tutorial.Date
val byte : value:'T -> byte (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.byte
--------------------
type byte = System.Byte
Full name: Microsoft.FSharp.Core.byte
val uint16 : value:'T -> uint16 (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.uint16
--------------------
type uint16 = System.UInt16
Full name: Microsoft.FSharp.Core.uint16
{Address: string option;
City: string option;
State: string option;
Country: string option;}
Full name: Tutorial.Location
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Core.option<_>
{Names: string [];
DOBs: Date [];
Citizenships: string [];
Locations: Location [];
Fields: Map<string,string>;}
Full name: Tutorial.Person
union case FieldAction.Map: Quotations.Expr -> FieldAction
--------------------
module Map
from Microsoft.FSharp.Collections
--------------------
type Map<'Key,'Value (requires comparison)> =
interface IEnumerable
interface IComparable
interface IEnumerable<KeyValuePair<'Key,'Value>>
interface ICollection<KeyValuePair<'Key,'Value>>
interface IDictionary<'Key,'Value>
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
member Add : key:'Key * value:'Value -> Map<'Key,'Value>
member ContainsKey : key:'Key -> bool
override Equals : obj -> bool
member Remove : key:'Key -> Map<'Key,'Value>
...
Full name: Microsoft.FSharp.Collections.Map<_,_>
--------------------
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
Full name: Tutorial.testPersons
Full name: Microsoft.FSharp.Collections.Map.empty
Full name: Tutorial.upperFunMapExpr
System.String.ToUpper(culture: System.Globalization.CultureInfo) : string
Full name: Tutorial.ex1
Full name: Microsoft.FSharp.Collections.Map.ofList
Full name: Fungible.Core.genrateRecordTransformFunction
{CloneWhenNoChanges: bool;
FailOnUnsupportedType: bool;}
static member Default : FungibleCoreSettings
Full name: Fungible.Core.FungibleCoreSettings
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
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<_>
Full name: Microsoft.FSharp.Collections.List.map
Full name: Tutorial.ex2
Full name: Tutorial.ex3
Full name: Tutorial.removeUpperVowelsExpr
from Microsoft.FSharp.Core
Full name: Microsoft.FSharp.Core.String.filter
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Array.contains
Full name: Microsoft.FSharp.Core.Operators.not
Full name: Tutorial.ex4
Full name: Tutorial.ex5
from Fungible
Full name: Tutorial.TestFunctions.Marker
Full name: Tutorial.TestFunctions.ModuleType
Full name: Microsoft.FSharp.Core.Operators.typeof
type TransformFunctionTypeAttribute =
inherit Attribute
new : ftype:String -> TransformFunctionTypeAttribute
member Type : String
member Type : String with set
Full name: Fungible.StaticReflection.TransformFunctionTypeAttribute
--------------------
new : ftype:String -> TransformFunctionTypeAttribute
type DescriptionAttribute =
inherit Attribute
new : unit -> DescriptionAttribute + 1 overload
member Description : string
member Equals : obj:obj -> bool
member GetHashCode : unit -> int
member IsDefaultAttribute : unit -> bool
static val Default : DescriptionAttribute
Full name: System.ComponentModel.DescriptionAttribute
--------------------
DescriptionAttribute() : unit
DescriptionAttribute(description: string) : unit
Full name: Tutorial.TestFunctions.removeCharacters
val char : value:'T -> char (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.char
--------------------
type char = Char
Full name: Microsoft.FSharp.Core.char
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
type StringBuilder =
new : unit -> StringBuilder + 5 overloads
member Append : value:string -> StringBuilder + 18 overloads
member AppendFormat : format:string * arg0:obj -> StringBuilder + 4 overloads
member AppendLine : unit -> StringBuilder + 1 overload
member Capacity : int with get, set
member Chars : int -> char with get, set
member Clear : unit -> StringBuilder
member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
member EnsureCapacity : capacity:int -> int
member Equals : sb:StringBuilder -> bool
...
Full name: System.Text.StringBuilder
--------------------
StringBuilder() : unit
StringBuilder(capacity: int) : unit
StringBuilder(value: string) : unit
StringBuilder(value: string, capacity: int) : unit
StringBuilder(capacity: int, maxCapacity: int) : unit
StringBuilder(value: string, startIndex: int, length: int, capacity: int) : unit
member Clone : unit -> obj
member CopyTo : array:Array * index:int -> unit + 1 overload
member GetEnumerator : unit -> IEnumerator
member GetLength : dimension:int -> int
member GetLongLength : dimension:int -> int64
member GetLowerBound : dimension:int -> int
member GetUpperBound : dimension:int -> int
member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
member Initialize : unit -> unit
member IsFixedSize : bool
...
Full name: System.Array
Array.IndexOf(array: Array, value: obj) : int
Array.IndexOf<'T>(array: 'T [], value: 'T, startIndex: int) : int
Array.IndexOf(array: Array, value: obj, startIndex: int) : int
Array.IndexOf<'T>(array: 'T [], value: 'T, startIndex: int, count: int) : int
Array.IndexOf(array: Array, value: obj, startIndex: int, count: int) : int
(+0 other overloads)
StringBuilder.Append(value: obj) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint64) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint32) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint16) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: decimal) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: float) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: float32) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: int64) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: int) : StringBuilder
(+0 other overloads)
Full name: Microsoft.FSharp.Core.Operators.ignore
StringBuilder.ToString(startIndex: int, length: int) : string
Full name: Tutorial.ex6_staticTransforms
Full name: Fungible.Core.getPathsAndTypes
Full name: Fungible.StaticReflection.generateTransform
from Tutorial
Full name: Tutorial.TestFunctions.ModuleType
Full name: Microsoft.FSharp.Collections.Array.map
Full name: Tutorial.ex6
Full name: Fungible.StaticReflection.compileTransforms
module Barb
from Fungible
--------------------
namespace Barb
from Barb
from Fungible
Full name: Tutorial.ex7_barbTransforms
{BindGlobalsWhenReducing: bool;
FailOnCatchAll: bool;
Namespaces: Set<string>;
AdditionalBindings: IDictionary<string,obj>;}
static member Default : BarbSettings
Full name: Barb.Representation.BarbSettings
Full name: Fungible.Barb.generateBarbTransform
Full name: Tutorial.ex7
Full name: Tutorial.ex8
Full name: Microsoft.FSharp.Collections.Array.append