Skip to content

Instantly share code, notes, and snippets.

@vagarenko
vagarenko / behavior.ts
Created Feb 5, 2018
Implementation of Functional Reactive Programming (FRP) concept of Behavior in Rx.js
View behavior.ts
import { BehaviorSubject, Observable, IDisposable } from 'rx';
/**
* Behavior represents a value that varies in time.
* Behavior is similar to `BehaviorSubject` because it always has value,
* but it's not `Subject`, that is you can't push values into it whenever you want.
* You can only subscribe it to an Observable once.
*/
export class Behavior<T> implements IDisposable {
/** Create a behavior that never changes. */
@vagarenko
vagarenko / maybe.ts
Last active Jul 13, 2021
Maybe type in Typescript.
View maybe.ts
/**
* The Maybe type encapsulates an optional value.
*/
export class Maybe<T> {
/** Create an empty value. */
static nothing<T>(): Maybe<T> {
return new Maybe<T>(undefined);
}
/** Create a non-empty value. */
@vagarenko
vagarenko / FreeCamera.hs
Last active Dec 16, 2017
Free camera controller from my 3D application. Depends on `reactive-banana>=1.1` and `static-tensor>=0.2.1`
View FreeCamera.hs
{-# LANGUAGE
TypeInType
, ExplicitForAll
, ScopedTypeVariables
, RecursiveDo
, TypeApplications
, TemplateHaskell
, FlexibleInstances
, MultiParamTypeClasses
, TypeFamilies
View hamming.hs
{-# LANGUAGE BangPatterns #-}
module Main where
import qualified Data.Text as Text
import Data.Text (Text, pack)
import Criterion.Main
import Test.QuickCheck.Arbitrary
import Test.QuickCheck
import Data.List
import qualified Data.Vector.Unboxed as U
@vagarenko
vagarenko / CheckedRevisited.hs
Created Jun 18, 2016 — forked from edsko/CheckedRevisited.hs
Lightweight checked exceptions in Haskell without `unsafeCoerce`
View CheckedRevisited.hs
{-# OPTIONS_GHC -Wall -fno-warn-unused-binds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE RoleAnnotations #-}
#endif
@vagarenko
vagarenko / Unboxed.hs
Created Nov 17, 2015
Unboxed polymorphic types
View Unboxed.hs
{-# LANGUAGE UnboxedTuples, MagicHash, TypeFamilies, DataKinds, PolyKinds, TypeOperators, DefaultSignatures #-}
{-# LANGUAGE KindSignatures, FlexibleInstances, FlexibleContexts #-}
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module Data.Unboxed where
import GHC.Exts
import GHC.Generics