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
import csv | |
import sys | |
class MachineStuck(Exception): | |
pass | |
class UnKnownOperation(Exception): | |
pass |
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
import Data.Bifunctor | |
import Data.Char | |
import Data.Functor.Const | |
import Data.Functor.Identity | |
import Prelude hiding (Maybe(..)) | |
newtype BiComp bf fu gu a b = | |
BiComp (bf (fu a) (gu b)) | |
instance (Bifunctor bf, Functor fu, Functor gu) => |
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
import re | |
def _parse_sequence(sequence): | |
remainder_to_parse = sequence | |
tokens = [] | |
while len(remainder_to_parse) > 0: | |
match2 = re.match(r"^(\(.*\))", remainder_to_parse) | |
if match2 is not None: | |
token = match2.group(1) |
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
from functools import reduce | |
from typing import List, Generic, Callable, TypeVar, Optional, Union | |
T = TypeVar('T') | |
Y = TypeVar('Y') | |
Z = TypeVar('Z') | |
class Maybe(Generic[T]): |
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
const applyReducer = (inputKeys, reducer, outputKeys, state, action) => { | |
// [NOTE] - need to handle the case where `state === undefined`.Indeed, | |
// Redux calls the reducers with an `undefined` state when | |
// the app is initializing. | |
const reducerArgs = inputKeys.map(key => (typeof state !== 'undefined' ? state[key] : undefined)) | |
.concat([action]) | |
const reduceResult = outputKeys.length === 1 ? [reducer(...reducerArgs)] : reducer(...reducerArgs) | |
return outputKeys.reduce( | |
(acc, key, index) => ({ ...acc, [key]: reduceResult[index] }), {}) | |
} |
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
from sys import modules | |
import inspect | |
def currying(elem): | |
""" | |
Decorator for currying a function. | |
f: (x, y) ->f(x, y) is transformed into g: x->f(x, elem) | |
:param elem: | |
:return: |