From b59328cd5655071b49b2b8894004b7b37b6939f7 Mon Sep 17 00:00:00 2001 From: Michael Martin-Smucker Date: Fri, 13 Dec 2019 10:52:22 -0700 Subject: [PATCH] Allow fold_map to map underlying type for Any/Plus --- src/interfaces/Interface.re | 4 ++-- test/Test_List.re | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interfaces/Interface.re b/src/interfaces/Interface.re index 2d2bd864..0fe15741 100644 --- a/src/interfaces/Interface.re +++ b/src/interfaces/Interface.re @@ -95,9 +95,9 @@ module type FOLDABLE = { module Fold_Map: (M: MONOID) => {let fold_map: ('a => M.t, t('a)) => M.t;}; module Fold_Map_Any: - (M: MONOID_ANY) => {let fold_map: ('a => M.t('a), t('a)) => M.t('a);}; + (M: MONOID_ANY) => {let fold_map: ('a => M.t('b), t('a)) => M.t('b);}; module Fold_Map_Plus: - (P: PLUS) => {let fold_map: ('a => P.t('a), t('a)) => P.t('a);}; + (P: PLUS) => {let fold_map: ('a => P.t('b), t('a)) => P.t('b);}; }; module type UNFOLDABLE = { diff --git a/test/Test_List.re b/test/Test_List.re index ee2e7c7c..efb5dbd4 100644 --- a/test/Test_List.re +++ b/test/Test_List.re @@ -114,6 +114,12 @@ describe("List", () => { expect(fold_map(List.Applicative.pure, [[1, 2, 3], [4, 5]])) |> to_be([[1, 2, 3], [4, 5]]); }); + + it("should do a map fold ('a => array('b))", () => { + let fold_map = ListF.Array.Fold_Map_Plus.fold_map; + expect(fold_map(Array.Applicative.pure <. Int.Show.show, [1, 2, 3])) + |> to_be([|"1", "2", "3"|]) + }); }); describe("Unfoldable", () => {