Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Restructure and vendor bs-rebel for dune build

+416 -51
+1
.gitignore
··· 30 30 node_modules/ 31 31 lib/ 32 32 src/**/*.js 33 + include/**/*.js 33 34 __tests__/**/*.js 34 35 coverage/ 35 36 _esy/
+15 -5
bsconfig.json
··· 1 1 { 2 2 "name": "wonka", 3 + "namespace": true, 3 4 "version": "0.1.0", 4 5 "bsc-flags": ["-bs-super-errors", "-bs-no-version-header"], 5 6 "refmt": 3, ··· 32 33 ] 33 34 }, 34 35 { 36 + "dir": "include", 37 + "subdirs": [ 38 + { 39 + "dir": "rebel_native" 40 + }, 41 + { 42 + "dir": "rebel_js", 43 + "backend": ["js"] 44 + } 45 + ] 46 + }, 47 + { 35 48 "dir": "__tests__", 36 49 "type": "dev" 37 50 } 38 51 ], 39 - "bs-dependencies" : [ 40 - "bs-rebel" 41 - ], 52 + "bs-dependencies" : [], 42 53 "bs-dev-dependencies": [ 43 54 "@glennsl/bs-jest" 44 - ], 45 - "namespace": false 55 + ] 46 56 }
+9
include/rebel.ml
··· 1 + #if BS_NATIVE then 2 + #if BSB_BACKEND = "js" then 3 + include Rebel_js 4 + #else 5 + include Rebel_native 6 + #end 7 + #else 8 + include Rebel_js 9 + #end
+97
include/rebel_js/Array_js.re
··· 1 + type t('a) = array('a); 2 + 3 + [@bs.new] external makeEmpty: unit => t('a) = "Array"; 4 + [@bs.new] external makeUninitialized: int => t('a) = "Array"; 5 + 6 + [@bs.get] external size: t('a) => int = "length"; 7 + [@bs.get_index] external get: (t('a), int) => option('a) = ""; 8 + [@bs.get_index] external getUnsafe: (t('a), int) => 'a = ""; 9 + [@bs.set_index] external setUnsafe: (t('a), int, 'a) => unit = ""; 10 + 11 + [@bs.send] external fill: (t('a), 'a) => unit = "fill"; 12 + [@bs.send] external reverseInPlace: t('a) => unit = "reverse"; 13 + 14 + [@bs.send] external copy: t('a) => t('a) = "slice"; 15 + [@bs.send] 16 + external slice: (t('a), ~start: int, ~end_: int) => t('a) = "slice"; 17 + [@bs.send] external sliceFrom: (t('a), int) => t('a) = "slice"; 18 + [@bs.send] external append: (t('a), 'a) => t('a) = "concat"; 19 + [@bs.send] external concat: (t('a), t('a)) => t('a) = "concat"; 20 + 21 + [@bs.send] external map: (t('a), 'a => 'b) => t('b) = "map"; 22 + [@bs.send] external mapi: (t('a), ('a, int) => 'b) => t('b) = "map"; 23 + [@bs.send] external some: (t('a), 'a => bool) => bool = "some"; 24 + [@bs.send] external somei: (t('a), ('a, int) => bool) => bool = "some"; 25 + [@bs.send] external every: (t('a), 'a => bool) => bool = "every"; 26 + [@bs.send] external everyi: (t('a), ('a, int) => bool) => bool = "every"; 27 + [@bs.send] external filter: (t('a), 'a => bool) => t('a) = "filter"; 28 + [@bs.send] external filteri: (t('a), ('a, int) => bool) => t('a) = "filter"; 29 + [@bs.send] external find: (t('a), 'a => bool) => option('a) = "find"; 30 + [@bs.send] external findi: (t('a), ('a, int) => bool) => option('a) = "find"; 31 + [@bs.send] external findIndex: (t('a), 'a => bool) => int = "findIndex"; 32 + [@bs.send] external forEach: (t('a), 'a => unit) => unit = "forEach"; 33 + [@bs.send] external forEachi: (t('a), ('a, int) => unit) => unit = "forEach"; 34 + [@bs.send] external reduce: (t('a), ('b, 'a) => 'b, 'b) => 'b = "reduce"; 35 + [@bs.send] 36 + external reducei: (t('a), ('b, 'a, int) => 'b, 'b) => 'b = "reduce"; 37 + [@bs.send] 38 + external reduceRight: (t('a), ('b, 'a) => 'b, 'b) => 'b = "reduceRight"; 39 + 40 + [@bs.send] external indexOf: (t('a), 'a) => int = "indexOf"; 41 + [@bs.send] external lastIndexOf: (t('a), 'a) => int = "lastIndexOf"; 42 + 43 + /* No need to replicate what Belt already has */ 44 + let shuffle = Belt.Array.shuffle; 45 + let shuffleInPlace = Belt.Array.shuffleInPlace; 46 + 47 + let make = (len: int, vals: 'a): t('a) => { 48 + let res = makeUninitialized(len); 49 + fill(res, vals); 50 + res; 51 + }; 52 + 53 + let set = (arr: t('a), index: int, x: 'a) => 54 + if (index < size(arr) && index >= 0) { 55 + setUnsafe(arr, index, x); 56 + true; 57 + } else { 58 + false; 59 + }; 60 + 61 + let reverse = (arr: t('a)): t('a) => { 62 + let res = copy(arr); 63 + reverseInPlace(arr); 64 + res; 65 + }; 66 + 67 + let includes = (arr: t('a), x: 'a): bool => indexOf(arr, x) > (-1); 68 + 69 + [@bs.send] external removeInPlace: (t('a), int) => t('a) = "splice"; 70 + [@bs.send] 71 + external removeCountInPlace: (t('a), ~pos: int, ~count: int) => t('a) = 72 + "splice"; 73 + 74 + let remove = (arr: t('a), pos: int) => removeInPlace(copy(arr), pos); 75 + 76 + let removeCount = (arr: t('a), ~pos: int, ~count: int) => 77 + removeCountInPlace(copy(arr), ~pos, ~count); 78 + 79 + module Js = { 80 + [@bs.send] external push: (t('a), 'a) => unit = "push"; 81 + [@bs.send] external pop: t('a) => option('a) = "pop"; 82 + [@bs.send] external unshift: (t('a), 'a) => unit = "unshift"; 83 + [@bs.send] external shift: t('a) => option('a) = "shift"; 84 + 85 + [@bs.scope ("Array", "prototype", "push")] [@bs.val] 86 + external pushMany: (t('a), t('a)) => unit = "apply"; 87 + [@bs.scope ("Array", "prototype", "unshift")] [@bs.val] 88 + external unshiftMany: (t('a), t('a)) => unit = "apply"; 89 + 90 + [@bs.send] 91 + external spliceInPlace: 92 + (t('a), ~pos: int, ~remove: int, ~add: t('a)) => t('a) = 93 + "splice"; 94 + 95 + let splice = (arr: t('a), ~pos: int, ~remove: int, ~add: t('a)) => 96 + spliceInPlace(copy(arr), ~pos, ~remove, ~add); 97 + };
+31
include/rebel_js/MutableQueue_js.re
··· 1 + type t('a) = array('a); 2 + 3 + external fromArray: array('a) => t('a) = "%identity"; 4 + external toArray: t('a) => array('a) = "%identity"; 5 + [@bs.new] external make: unit => t('a) = "Array"; 6 + [@bs.set] external clear: (t('a), [@bs.as 0] _) => unit = "length"; 7 + [@bs.send] external add: (t('a), 'a) => unit = "push"; 8 + [@bs.get] external peek: t('a) => option('a) = "0"; 9 + [@bs.send] external pop: t('a) => option('a) = "shift"; 10 + [@bs.send] external copy: t('a) => t('a) = "slice"; 11 + [@bs.get] external size: t('a) => int = "length"; 12 + [@bs.send] external mapU: (t('a), (. 'a) => 'b) => t('b) = "map"; 13 + [@bs.send] external map: (t('a), 'a => 'b) => t('b) = "map"; 14 + [@bs.send] external forEachU: (t('a), (. 'a) => unit) => unit = "forEach"; 15 + [@bs.send] external forEach: (t('a), 'a => unit) => unit = "forEach"; 16 + 17 + let isEmpty = (q: t('a)): bool => size(q) === 0; 18 + 19 + let reduceU = (q: t('a), accu: 'b, f: (. 'b, 'a) => 'b): 'b => 20 + Js.Array.reduce((acc, x) => f(. acc, x), accu, q); 21 + 22 + let reduce = (q: t('a), accu: 'b, f: ('b, 'a) => 'b): 'b => 23 + Js.Array.reduce(f, accu, q); 24 + 25 + [@bs.scope ("Array", "prototype", "push")] [@bs.val] 26 + external addMany: (t('a), t('a)) => unit = "apply"; 27 + 28 + let transfer = (q1: t('a), q2: t('a)) => { 29 + addMany(q1, q2); 30 + clear(q1); 31 + };
+19
include/rebel_js/MutableStack_js.re
··· 1 + type t('a) = array('a); 2 + 3 + module Helpers = { 4 + [@bs.get_index] external get: (t('a), int) => option('a) = ""; 5 + }; 6 + 7 + [@bs.new] external make: unit => t('a) = "Array"; 8 + [@bs.set] external clear: (t('a), [@bs.as 0] _) => unit = "length"; 9 + [@bs.send] external push: (t('a), 'a) => unit = "push"; 10 + [@bs.send] external pop: t('a) => option('a) = "pop"; 11 + [@bs.send] external copy: t('a) => t('a) = "slice"; 12 + [@bs.get] external size: t('a) => int = "length"; 13 + [@bs.send] external forEachU: (t('a), (. 'a) => unit) => unit = "forEach"; 14 + [@bs.send] external forEach: (t('a), 'a => unit) => unit = "forEach"; 15 + 16 + let isEmpty = (stack: t('a)): bool => size(stack) === 0; 17 + 18 + let top = (stack: t('a)): option('a) => 19 + Helpers.get(stack, size(stack) - 1);
+3
include/rebel_js/Rebel_js.re
··· 1 + module Array = Array_js; 2 + module MutableStack = MutableStack_js; 3 + module MutableQueue = MutableQueue_js;
+170
include/rebel_native/Array_native.re
··· 1 + type t('a) = array('a); 2 + 3 + let makeEmpty = (): t('a) => [||]; 4 + let makeUninitialized = Belt.Array.makeUninitializedUnsafe; 5 + let make = Belt.Array.make; 6 + 7 + let size = Belt.Array.size; 8 + let get = Belt.Array.get; 9 + let getUnsafe = Belt.Array.getUnsafe; 10 + let set = Belt.Array.set; 11 + let setUnsafe = Belt.Array.setUnsafe; 12 + 13 + let fill = (arr: t('a), x: 'a) => 14 + Belt.Array.fill(arr, ~offset=0, ~len=size(arr), x); 15 + 16 + let reverseInPlace = Belt.Array.reverseInPlace; 17 + let reverse = Belt.Array.reverse; 18 + let shuffle = Belt.Array.shuffle; 19 + let shuffleInPlace = Belt.Array.shuffleInPlace; 20 + 21 + let copy = Belt.Array.copy; 22 + 23 + let slice = (arr: t('a), ~start: int, ~end_: int): t('a) => { 24 + let len = end_ - start; 25 + Belt.Array.slice(arr, ~offset=start, ~len); 26 + }; 27 + 28 + let sliceFrom = Belt.Array.sliceToEnd; 29 + let concat = Belt.Array.concat; 30 + 31 + let append = (arr: t('a), x: 'a) => Belt.Array.concat(arr, [|x|]); 32 + 33 + let somei = (arr: t('a), f: ('a, int) => bool): bool => { 34 + let len = size(arr); 35 + let rec search = (i: int) => 36 + if (i >= len) { 37 + false; 38 + } else if (f(getUnsafe(arr, i), i)) { 39 + true; 40 + } else { 41 + search(i + 1); 42 + }; 43 + 44 + search(0); 45 + }; 46 + 47 + let everyi = (arr: t('a), f: ('a, int) => bool): bool => { 48 + let len = size(arr); 49 + let rec search = (i: int) => 50 + if (i >= len) { 51 + true; 52 + } else if (!f(getUnsafe(arr, i), i)) { 53 + false; 54 + } else { 55 + search(i + 1); 56 + }; 57 + 58 + search(0); 59 + }; 60 + 61 + let findi = (arr: t('a), f: ('a, int) => bool): option('a) => { 62 + let len = size(arr); 63 + let rec search = (i: int) => 64 + if (i >= len) { 65 + None; 66 + } else { 67 + let x = getUnsafe(arr, i); 68 + if (f(x, i)) { 69 + Some(x); 70 + } else { 71 + search(i + 1); 72 + }; 73 + }; 74 + 75 + search(0); 76 + }; 77 + 78 + let findIndex = (arr: t('a), f: 'a => bool): int => { 79 + let len = size(arr); 80 + let rec search = (i: int) => 81 + if (i >= len) { 82 + (-1); 83 + } else if (f(getUnsafe(arr, i))) { 84 + i; 85 + } else { 86 + search(i + 1); 87 + }; 88 + 89 + search(0); 90 + }; 91 + 92 + let lastIndexOf = (arr: t('a), x: 'a): int => { 93 + let len = size(arr); 94 + let rec search = (i: int) => 95 + if (i < 0) { 96 + (-1); 97 + } else if (x === getUnsafe(arr, i)) { 98 + i; 99 + } else { 100 + search(i - 1); 101 + }; 102 + 103 + search(len - 1); 104 + }; 105 + 106 + let filteri = (arr: t('a), f: ('a, int) => bool): t('a) => { 107 + let len = size(arr); 108 + let res = makeUninitialized(len); 109 + let j = ref(-1); 110 + 111 + let rec filter = (i: int) => 112 + if (i >= len) { 113 + Belt.Array.truncateToLengthUnsafe(res, j^ + 1); 114 + res; 115 + } else { 116 + let x = getUnsafe(arr, i); 117 + if (f(x, i)) { 118 + j := j^ + 1; 119 + Belt.Array.setUnsafe(arr, j^, x); 120 + }; 121 + 122 + filter(i + 1); 123 + }; 124 + 125 + filter(0); 126 + }; 127 + 128 + let removeCount = (arr: t('a), ~pos: int, ~count: int): t('a) => { 129 + let len = size(arr); 130 + let pos2 = pos + count - 1; 131 + let res = makeUninitialized(len - count); 132 + 133 + let rec copy = (i: int) => 134 + if (i >= len) { 135 + res; 136 + } else if (i >= pos && i <= pos2) { 137 + copy(i + 1); 138 + } else { 139 + let j = i > pos2 ? i - count : i; 140 + Belt.Array.setUnsafe(arr, j, Belt.Array.getUnsafe(arr, i)); 141 + copy(i + 1); 142 + }; 143 + 144 + copy(0); 145 + }; 146 + 147 + let find = (arr: t('a), f: 'a => bool): option('a) => 148 + findi(arr, (x, _i) => f(x)); 149 + let indexOf = (arr: t('a), x: 'a): int => findIndex(arr, item => item === x); 150 + let includes = (arr: t('a), x: 'a): bool => 151 + findIndex(arr, item => item === x) > (-1); 152 + let filter = (arr: t('a), f: 'a => bool): t('a) => 153 + filteri(arr, (x, _i) => f(x)); 154 + let remove = (arr: t('a), index: int): t('a) => 155 + removeCount(arr, ~pos=index, ~count=1); 156 + 157 + let some = Belt.Array.some; 158 + let every = Belt.Array.every; 159 + let map = Belt.Array.map; 160 + let mapi = (arr: t('a), f: ('a, int) => 'b): t('b) => 161 + Belt.Array.mapWithIndexU(arr, (. i, x) => f(x, i)); 162 + let forEach = Belt.Array.forEach; 163 + let forEachi = (arr: t('a), f: ('a, int) => unit): unit => 164 + Belt.Array.forEachWithIndexU(arr, (. i, x) => f(x, i)); 165 + let reduce = (arr: t('a), reducer: ('b, 'a) => 'b, acc: 'b): 'b => 166 + Belt.Array.reduce(arr, acc, reducer); 167 + let reducei = (arr: t('a), reducer: ('b, 'a, int) => 'b, acc: 'b): 'b => 168 + Belt.Array.reduceWithIndex(arr, acc, reducer); 169 + let reduceRight = (arr: t('a), reducer: ('b, 'a) => 'b, acc: 'b): 'b => 170 + Belt.Array.reduceReverse(arr, acc, reducer);
+24
include/rebel_native/MutableQueue_native.re
··· 1 + type t('a) = Belt.MutableQueue.t('a); 2 + 3 + let fromArray = Belt.MutableQueue.fromArray; 4 + let toArray = Belt.MutableQueue.toArray; 5 + let make = Belt.MutableQueue.make; 6 + let clear = Belt.MutableQueue.clear; 7 + let add = Belt.MutableQueue.add; 8 + let peek = Belt.MutableQueue.peek; 9 + let pop = Belt.MutableQueue.pop; 10 + let copy = Belt.MutableQueue.copy; 11 + let size = Belt.MutableQueue.size; 12 + let mapU = Belt.MutableQueue.mapU; 13 + let map = Belt.MutableQueue.map; 14 + let forEachU = Belt.MutableQueue.forEachU; 15 + let forEach = Belt.MutableQueue.forEach; 16 + 17 + let isEmpty = Belt.MutableQueue.isEmpty; 18 + let reduceU = Belt.MutableQueue.reduceU; 19 + let reduce = Belt.MutableQueue.reduce; 20 + 21 + let addMany = (q1: t('a), q2: t('a)) => 22 + Belt.MutableQueue.transfer(copy(q1), q2); 23 + 24 + let transfer = Belt.MutableQueue.transfer;
+13
include/rebel_native/MutableStack_native.re
··· 1 + type t('a) = Belt.MutableStack.t('a); 2 + 3 + let make = Belt.MutableStack.make; 4 + let clear = Belt.MutableStack.clear; 5 + let push = Belt.MutableStack.push; 6 + let pop = Belt.MutableStack.pop; 7 + let copy = Belt.MutableStack.copy; 8 + let size = Belt.MutableStack.size; 9 + let forEachU = Belt.MutableStack.forEachU; 10 + let forEach = Belt.MutableStack.forEach; 11 + 12 + let isEmpty = Belt.MutableStack.isEmpty; 13 + let top = Belt.MutableStack.top;
+3
include/rebel_native/Rebel_native.re
··· 1 + module Array = Array_native; 2 + module MutableStack = MutableStack_native; 3 + module MutableQueue = MutableQueue_native;
+2 -10
package.json
··· 40 40 "homepage": "https://github.com/kitten/wonka", 41 41 "bugs": "https://github.com/kitten/wonka/issues", 42 42 "license": "MIT", 43 - "dependencies": { 44 - "bs-rebel": "^0.2.3" 45 - }, 43 + "dependencies": {}, 46 44 "devDependencies": { 47 45 "@glennsl/bs-jest": "^0.4.8", 48 46 "bs-platform": "^5.0.4", ··· 83 81 "testMatch": [ 84 82 "**/lib/js/__tests__/*_test.js" 85 83 ] 86 - }, 87 - "bundlesize": [ 88 - { 89 - "path": "./dist/wonka.es.js", 90 - "maxSize": "9 kB" 91 - } 92 - ] 84 + } 93 85 }
+3 -31
src/wonka.ml
··· 1 1 module Types = Wonka_types 2 2 3 - (* sources *) 4 - include Wonka_source_fromArray 5 - include Wonka_source_fromList 6 - include Wonka_source_fromValue 7 - include Wonka_source_make 8 - include Wonka_source_makeSubject 9 - include Wonka_source_primitives 10 - 11 - (* operators *) 12 - include Wonka_operator_combine 13 - include Wonka_operator_concatMap 14 - include Wonka_operator_filter 15 - include Wonka_operator_map 16 - include Wonka_operator_mergeMap 17 - include Wonka_operator_onEnd 18 - include Wonka_operator_onPush 19 - include Wonka_operator_onStart 20 - include Wonka_operator_scan 21 - include Wonka_operator_share 22 - include Wonka_operator_skip 23 - include Wonka_operator_skipUntil 24 - include Wonka_operator_skipWhile 25 - include Wonka_operator_switchMap 26 - include Wonka_operator_take 27 - include Wonka_operator_takeLast 28 - include Wonka_operator_takeUntil 29 - include Wonka_operator_takeWhile 30 - 31 - (* sinks *) 32 - include Wonka_sink_publish 33 - include Wonka_sink_subscribe 3 + include Wonka_sources 4 + include Wonka_operators 5 + include Wonka_sinks 34 6 35 7 #if BS_NATIVE then 36 8 #if BSB_BACKEND = "js" then
+18
src/wonka_operators.re
··· 1 + include Wonka_operator_combine; 2 + include Wonka_operator_concatMap; 3 + include Wonka_operator_filter; 4 + include Wonka_operator_map; 5 + include Wonka_operator_mergeMap; 6 + include Wonka_operator_onEnd; 7 + include Wonka_operator_onPush; 8 + include Wonka_operator_onStart; 9 + include Wonka_operator_scan; 10 + include Wonka_operator_share; 11 + include Wonka_operator_skip; 12 + include Wonka_operator_skipUntil; 13 + include Wonka_operator_skipWhile; 14 + include Wonka_operator_switchMap; 15 + include Wonka_operator_take; 16 + include Wonka_operator_takeLast; 17 + include Wonka_operator_takeUntil; 18 + include Wonka_operator_takeWhile;
+2
src/wonka_sinks.re
··· 1 + include Wonka_sink_publish; 2 + include Wonka_sink_subscribe;
+6
src/wonka_sources.re
··· 1 + include Wonka_source_fromArray; 2 + include Wonka_source_fromList; 3 + include Wonka_source_fromValue; 4 + include Wonka_source_make; 5 + include Wonka_source_makeSubject; 6 + include Wonka_source_primitives;
-5
yarn.lock
··· 716 716 resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-5.0.4.tgz#d406ef43c12d1b19d8546884d8b5b4e0fb709372" 717 717 integrity sha512-rXM+ztN8wYXQ4ojfFGylvPOf8GRLOvM94QJsMMV9VpsLChKCjesWMNybTZvpoyNsESu2nC5q+C9soG+BPhuUFQ== 718 718 719 - bs-rebel@^0.2.3: 720 - version "0.2.3" 721 - resolved "https://registry.yarnpkg.com/bs-rebel/-/bs-rebel-0.2.3.tgz#11e1a95a4a3f16311575e8853a004cec6b9d19de" 722 - integrity sha512-NTDUSkJ+KkIqmKHUE48luD2YaYh49XaU1zVSSk9lJ6KFNQzlRQnIfR+paNWYyvzxf5+TZ2inVgxBUHdCsZEiYA== 723 - 724 719 bser@^2.0.0: 725 720 version "2.0.0" 726 721 resolved "https://registry.yarnpkg.com/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719"