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
module Reader exposing | |
( return | |
, ask | |
, runReader | |
, local | |
, fmap | |
, chain | |
) | |
type Reader r a = Reader (r -> 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
https://flems.io/#0=N4IgZglgNgpgziAXAbVAOwIYFsZJAOgAsAXLKEAGhAGMB7NYmBvAHhLID4AdNNmDACbc0AAhEs41AE4QADsRFwp1ALxcQJYrLiIA9LoCuaWQGsA5vjpZDaCPQC0xAJ6yYAAQAM+ACz4AjLoCEHDENnZoji4w+ABWcOocLLqSMvLCYkmE-EI8GQBGtAJO6eK6BUXCmaRQHJQgcDCw1MThCIggAEyIAGwAHCAAvhTo2LjtUBB5sQhUdAxMxHgQWLK0UgrAIlJMAjBSIgMiYFK0WCIA5JraejamFla67Lqy2xjNycQYaAIYUPTRWEKBlg03OPB4MAAHqt1kcjM1wkcTlgAKIANwWAApnK4KCJGjAcAwAJQiYC5LYwYgGKSiMDwlr0TFoKHEUnk0RifGwInEfCCATohYAGWCjBZUmxUTxLMhbIpAx4irQEOhawU9LQCPoIiwGFkmLAeKU1HZFO21NpcK1jLQzNZZs5YhNmLRvxEKg4IllxENrt+xMDCqV4NlMI1DMRnwNkLxYEdYjAmMhxPNVJpokhIZVYfV1u1ohwUjMMGTcATlMtdMjTJ9FbEkLg+G2AgM1FL0ZlDuDaGVqvD+dtRyp1EIQoYmJpUArFozg-C9rl9eHxFHk6k04pXJE+GIWTt2zgsg9XsPsmmTKDTq5u-3i-l17Elgwq8I99TnOVfdzsM1BaOtBQAIBpgGgeIQLYLS-MaygzumVp-kO75kluIiwAobzUB6IgQRAUFQKhPqYphH7bi6iELmiy5iJh2GgcR1DUHiVGoWIREkahAykQc2b9nmFE6ts3x7AAIgA8gAspiJrMRAMAAO54o0WBwVW861g6KHXuRNZ2j8nzUd6rKYkJuySmicnyZi+kYMSSlQCp3FiFxPbflCA5zCEOECNhkIniIWY5u5eaeRhUDyRgThwNhGD+Xk-kYKGwW-rpWxGNJsFac6yiYhAAgfm5aopTaiIhBg6wAOp4W+saKJlHJiLOCG6chDVckRKaoS |
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
// how would you programmatically create a list of 3 elements and set to the DOM | |
// the data should come from a external entity like a third party source ie https://reqres.in/api/users | |
/* | |
should result into | |
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
</ul> | |
*/ |
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
module Main where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Data.Foldable (fold) | |
import TryPureScript (DOM, p, render, text) | |
data Maybe a = Just a | Nothing |
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 obj = { 1: {}, 2: {}, 3: {} } | |
const calculateLimitedPermutation = (pFn , aFn, o) => { | |
const recurse = (index = 0, xs = []) => { | |
const arr = Object.keys(o) | |
if ( arr.length === 0 ) return o; | |
const types = arr.reduce( | |
(acc, key, idx) => | |
idx === index | |
? { ...acc, ...{ [key]: pFn(key) } } |
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 toString = buff => buff.toString() | |
const jParse = str => JSON.parse(str) | |
const stringify = obj => JSON.stringify(obj) | |
const keys = obj => Object.keys(obj) | |
const dissoc = (str, obj) => | |
keys(obj).reduce((acc, k) => k !== str ? (acc[k] = obj[k], acc) : acc , {}) | |
const simpleReq = (url, opts = {}) => | |
new Promise((resolve, reject) => { |
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
// Array#reduce + recursion to flatten | |
// any level of nested arrays | |
// So we reduce the nested array and aggregate the values of the Integer type into the seed array | |
// during the aggregation we 1st check if the values from the input array are of the Array type via `isArray` | |
// if so we call the function `flatten` again passing that array value as input and if the value is | |
// not of the Array type it we `concat` the value with the seed array | |
// below is a timeline of how the values look after the input array is given | |
// [[1, 2, [3]], 4]: --- [1,2,[3]] --> 1 --> 2 --> [3] --> 3 --> 4 | |
const flatten = array => array.reduce((acc, val) => acc.concat(Array.isArray(x) ? flatten(val) : val), []) |
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 Coyo = (f, v) => ({fn: f, val: v}) | |
const id = x => x | |
const liftCoyo = a => Coyo(id, a) | |
const fmap = (fn, coyo) => Coyo(compose(fn, coyo.fn), coyo.val) | |
const lower = coyo => map(coyo.fn, coyo.val) |
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
// @TODO pull out the mapping and filtering | |
// make composable/lazy(only run when fold'ing) | |
const copyList = xs => reduce(concat, [], xs) | |
const filterR = (f, xs) => reduce((acc, x) => f(x) ? acc.concat(x) : acc , [], xs) | |
const mapR = (f, xs) => reduce((acc, x) => acc.concat(f(x)), [], xs) | |
// List with methods in terms of reduce | |
const List = xs => ({ | |
xs, | |
map: f => List(mapR(f, xs)), |
NewerOlder