A lens library for functional programming in MoonScript.
{
"deps": {
"sennenki/lens": "0.1.0"
}
}let lens = Lens::fst()
let pair = (1, 2)
// Get
lens.get(pair) // 1
// Set
lens.set(pair, 3) // (3, 2)let l1 = Lens::fst()
let l2 = Lens::snd()
// Focus on the second element of the first element of a nested pair
let composed = l1.compose(l2) // Lens[((Int, Int), Int), Int]
composed.get(((1, 2), 3)) // 2let prism = Prism::some()
prism.get(Some(42)) // Some(42)
prism.get(None) // None
prism.set(Some(1), 2) // Some(2)let iso = Iso::array_list()
iso.to([1, 2, 3]) // List::[1, 2, 3]
iso.from(@list.from_array([1, 2, 3])) // [1, 2, 3]type Epi[A, B]type Iso[A, B]type Lens[A, B]type Prism[A, B]Install
Download zipA lens library for functional programming in MoonScript.