Skip to content

Instantly share code, notes, and snippets.

View charlesroddie's full-sized avatar

Charles Roddie charlesroddie

  • Summatic
  • Cambridge, UK
View GitHub Profile
module Block =
open System.Collections.Generic
// I find it convenient in `let ia = l |> Block.map f`, for l to be allowed to be a list or block.
// This helps to convert lists to blocks in APIs where existing users expect to input lists.
// Alternatively, this could be an additional method mapFromCollection
let mapVersionA<'a, 'b> (f:'a -> 'b) (arr:IReadOnlyCollection<'a>) =
// note that null reference check shouldn't be needed any more as nulls are rapidly
// becoming a non-issue in .Net and that will apply to F# when NRT support is implemented
let builder = ImmutableArray.CreateBuilder<'b>(arr.Count)
namespace XamarinHelpers
open Xamarin.Forms
type Grid with
member t.RowHeights
with set l =
t.RowDefinitions.Clear()
for gl in l do t.RowDefinitions.Add(RowDefinition(Height = gl))
member t.Rows with set (l: seq<seq<View>>) =
@charlesroddie
charlesroddie / SerializationExample.fs
Last active March 9, 2019 13:42
FSharp serializer example
// Could use NewtonSoft intead but the API is a little less clean, and NewtonSoft is limited to Json.
open PeterO.Cbor
open System
// from https://www.znprojects.com/2019/03/daily-coding-problem-3.html
type DUNode =
| Node of string * left:DUNode option * right:DUNode option
[<AutoOpen>]
module CBORHelpers =
@charlesroddie
charlesroddie / Input.fs
Last active November 27, 2018 12:45
FSharp Input Model
// Initial draft of F# Input Model.
// To input an F# type T, define an function T -> Input and a function ReceivedInput -> T.
// An InputView can be defined that takes an Input. It gives a ReceivedInput when the input is complete.
// Validation needs to be added.
[<RequireQualifiedAccess>]
type Input =
| Int
| Float
| DU of (string * (unit -> Input))[]