/* * Copyright 2020 Matthew Lutze, Esben Bjerre, Magnus Madsen * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Trait for types that can be mapped over, and its functions.///pubmod Functor {////// Trait for types that can be mapped over.///pubtraitFunctor[m: Type -> Type] {////// Applies the function `f` to `x` preserving its structure.///pubdefmap(f: a -> b \ ef, x: m[a]): m[b] \ ef }////// Replaces the value `a` in `s` by the given value `x` preserving the structure of `s`.///pubdefreplace [a: Type, b: Type, m: Type -> Type] (s: m[a], x: b): m[b] withFunctor[m] = Functor.map(_ -> x, s)////// Replaces the value `a` in `s` with `Unit` preserving the structure of `s`.////// This function is typically used to discard the return value of computing `s`.///pubdefignore(s: m[a]): m[Unit] withFunctor[m] = s`Functor.replace`()////// `<$>` is an operator alias for `map`.///pubdef<$>(f: a -> b \ ef, x: m[a]): m[b] \ efwithFunctor[m] = Functor.map(f, x)////// `<$$>` is the operator `<$>` with its arguments flipped.///pubdef<$$>(x: m[a], f: a -> b \ ef): m[b] \ efwithFunctor[m] = Functor.map(f, x)////// `<$` is the operator `$>` with its arguments flipped.///pubdef<$(x: a, ma: f[b]): f[a] withFunctor[f] = Functor.replace(ma, x)////// `$>` is an operator alias for `replace`.///pubdef$>(ma: f[a], x: b): f[b] withFunctor[f] = Functor.replace(ma, x)}