This file contains hidden or 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
function flip<A, B, C>(f: (a0: A, a1: B) => C): (b0: B, b1: A) => C { | |
return (b0: B, b1: A) => { | |
return f(b1, b0); | |
} | |
} | |
// ==== TEST ==== | |
const x: string = 'test'; | |
const y: number = 1; |
This file contains hidden or 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
// | |
// Created with help of the great contents from: | |
// http://learnyouahaskell.com/a-fistful-of-monads | |
// | |
// Just a helper type to define exact type of a basic function with one input and output. | |
type BasicFn<A, B> = (input: A) => B; | |
// Wrapper interface for Monad valueOf return value, to differentiate from other return types. | |
interface IMonadValueOf<A> { |
This file contains hidden or 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
-- http://learnyouahaskell.com/modules#making-our-own-modules | |
module User ( | |
Account, | |
AccountRole, | |
accounts, | |
isAccountRoleEqual, | |
isAccountRoleSet, | |
filterAccountsWithRoleSet, | |
filterAccountsByRole, | |
filterAccountsByAdminRole |
This file contains hidden or 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
// Heavily based on this great article by Eric Elliott: | |
// https://medium.com/javascript-scene/javascript-monads-made-simple-7856be57bfe8 | |
const main1 = () => { | |
const compose = (f, g) => (x) => f(g(x)); | |
// g :: Integer -> [Integer] | |
const g = (a) => Array.of(a); | |
// f :: [Integer] -> Bool |
This file contains hidden or 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 PRIMITIVE_TYPES = { | |
string: true, | |
number: true, | |
bigint: true, | |
boolean: true, | |
symbol: true, | |
undefined: true | |
}; | |
function isPrimitive(value) { |
This file contains hidden or 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 Nothing = Symbol('Nothing'); | |
const Just = (value) => Symbol("Just " + JSON.stringify(value)); | |
const isAssocList = (value) => { | |
return Array.isArray(value) && value.length === 2; | |
}; | |
const findAssocListValueByKey = (list, key) => { | |
const [assocItem, ...items] = list; | |
if (undefined === assocItem) { |
This file contains hidden or 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 tuple = (...atoms) => Object.freeze( | |
atoms.reduce((partial, atom, index) => ({ | |
...partial, | |
['_' + ++index]: atom | |
}), {}) | |
); |
This file contains hidden or 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 {case_spec, match_spec} from './lib.mjs'; | |
const _case = (expression) => { | |
return { | |
of: (...predicates) => { | |
return case_spec(expression, () => predicates.reduce((partial, expr) => { | |
return { | |
...partial, | |
[match_spec(expression, expr.matchSpec)]: expr.matchFn | |
}; |
This file contains hidden or 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 usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const useErlangStyleString = (string, resultString) => { | |
const length = string.length; | |
if (!length) { | |
return resultString; | |
} |
This file contains hidden or 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 usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const listReverseState = (list, reversedList, acc) => { | |
const [head, tail] = usePrologStyleList(list); | |
if (head === undefined) { | |
return reversedList = acc; |