Hobby / Monadic Vue.js
https://github.com/ubugeeei/monadic-vue.git
This is a hobby project. Not intended for production use.
Vue Reactivity (Ref) as Monad, Comonad, and Bimonad.
Based on the observation that Vue's Ref satisfies both Monad laws and Comonad laws (under extensional equality).
All multi-argument functions are curried (data-first for TypeScript inference).
map(refA)((a) => b) โ Ref(A) โ (A โ B) โ Ref(B)pure(value) โ ฮท: A โ Ref(A)flat(refRefA) โ ฮผ: Ref(Ref(A)) โ Ref(A)flatMap(refA)((a) => refB) โ >>=: Ref(A) โ (A โ Ref(B)) โ Ref(B)wrap(innerRef) โ creates Ref(Ref(A)) without Vue auto-unwrappingextr(refA) โ ฮต: Ref(A) โ Aextd(refA)((w) => b) โ Ref(A) โ (Ref(A) โ B) โ Ref(B)dup(refA) โ ฮด: Ref(A) โ Ref(Ref(A))comp(f)(g) โ Kleisli: (A โ Ref(B)) โ (B โ Ref(C)) โ (A โ Ref(C))pipe(refA, f, g, ...) โ do-notation-like chainingimport { ref } from "vue";
import { flatMap, pure, extr, extd, map } from "monadic-vue";
const count = ref(3);
const items = ref([10, 20, 30, 40, 50]);
// Monadic flatMap (data-first โ types inferred)
const sliced = flatMap(count)((n) =>
flatMap(items)((list) => ref(list.slice(0, n))),
);
// Comonadic extd
const doubled = extd(count)((w) => extr(w) * 2);
// Functor map
const label = map(count)((n) => `count: ${n}`);
// Bimonad compatibility: ฮต โ ฮท = id
extr(pure(42)); // 42
MIT