Skip to content

Instantly share code, notes, and snippets.

View ivelten's full-sized avatar

Ismael Carlos Velten ivelten

  • Paybyrd
  • Brazil
View GitHub Profile
@ivelten
ivelten / Values.fs
Created August 6, 2019 14:55
Smart value
open System.Threading.Tasks
open FSharp.Control.Tasks.V2
[<RequireQualifiedAccess>]
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Lazy =
let map (fn : 'T -> 'U) (x : Lazy<'T>) =
Lazy.Create(fun () -> fn x.Value)
[<Struct>]
@ivelten
ivelten / Validation.fs
Last active July 3, 2019 21:01
Validation refactoring
/// The MIT License (MIT)
/// Copyright (c) 2016 Bazinga Technologies Inc
module FSharp.Data.GraphQL.Validation.Ast
open FSharp.Data.GraphQL.Types
open FSharp.Data.GraphQL.Introspection
type ValidationTypeRef =
| NonNull of ValidationTypeRef
@ivelten
ivelten / IDictionaryConverter.fs
Created June 10, 2019 13:51
A JsonConverter which recursively converts objects into dictonary types
[<Sealed>]
type IDictionaryConverter() =
inherit JsonConverter()
let fail() = raise <| JsonSerializationException("Unexpected end when reading a JSON object into an IDictionary<string, object>.")
let rec writeObject (writer : JsonWriter) (value : obj) =
writer.WriteStartObject()
value :?> IDictionary<string, obj>
|> Seq.iter (fun kvp ->
@ivelten
ivelten / Program.fs
Created May 3, 2019 20:42
GraphQL Client
open FSharp.Data.GraphQL
type MyProvider = GraphQLProvider<"http://localhost:8084">
[<EntryPoint>]
let main _ =
let ball = MyProvider.Types.Ball(form = "Spheric", format = "Spheric", id = "1")
let box = MyProvider.Types.Box(form = "Cubic", format = "Cubic", id = "2")
let things : MyProvider.Types.IThing list = [ball; box]
@ivelten
ivelten / ObservableExtensions.fs
Created December 15, 2018 16:34
Observable extensions
open System.Reactive.Linq
open System
/// Extended operations on observable objects.
[<RequireQualifiedAccess>]
module Observable =
/// Binds an observable sequence using the provided binder function to produce a new observable.
let bind (binder : 'a -> IObservable<'b>) x = Observable.SelectMany(x, binder)
/// Creates an observable sequence from an asynchronous computation.
@ivelten
ivelten / AsyncVal.fs
Last active December 15, 2018 16:21
A struct used to operate on both synchornous values and asynchronous computations
open Microsoft.FSharp.Control
open System.Collections.Generic
open System.Reactive.Linq
/// A struct used to operate on both synchornous values and asynchronous computations.
/// Can hold computation failures as exceptions as well.
type AsyncVal<'a> =
/// Represents a synchronous value.
| Value of 'a
/// Represents an asynchronous computation.