From 5fbd1453b4e06ce0dd4579605ba0ceb777eed62a Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 9 Dec 2022 10:40:31 +0100 Subject: [PATCH 1/3] can now add bare numbers to numeral object props --- packages/core/value.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/value.mjs b/packages/core/value.mjs index 7eb89013..49f66bd1 100644 --- a/packages/core/value.mjs +++ b/packages/core/value.mjs @@ -7,6 +7,12 @@ This program is free software: you can redistribute it and/or modify it under th import { curry } from './util.mjs'; export function unionWithObj(a, b, func) { + if (typeof b?.value === 'number') { + // https://github.com/tidalcycles/strudel/issues/262 + const numKeys = Object.keys(a).filter((k) => typeof a[k] === 'number'); + const numerals = Object.fromEntries(numKeys.map((k) => [k, b.value])); + b = Object.assign(b, numerals); + } const common = Object.keys(a).filter((k) => Object.keys(b).includes(k)); return Object.assign({}, a, b, Object.fromEntries(common.map((k) => [k, func(a[k], b[k])]))); } From a45d63595f1ccd736d0ae7b8208d036073a3b6e4 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 9 Dec 2022 11:00:28 +0100 Subject: [PATCH 2/3] delete bare value before numeral union --- packages/core/value.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/value.mjs b/packages/core/value.mjs index 49f66bd1..f9a963ce 100644 --- a/packages/core/value.mjs +++ b/packages/core/value.mjs @@ -12,6 +12,7 @@ export function unionWithObj(a, b, func) { const numKeys = Object.keys(a).filter((k) => typeof a[k] === 'number'); const numerals = Object.fromEntries(numKeys.map((k) => [k, b.value])); b = Object.assign(b, numerals); + delete b.value; } const common = Object.keys(a).filter((k) => Object.keys(b).includes(k)); return Object.assign({}, a, b, Object.fromEntries(common.map((k) => [k, func(a[k], b[k])]))); From def6bbf683ab00cc33140c176caa0c33843cbb3f Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 11 Dec 2022 21:43:05 +0100 Subject: [PATCH 3/3] add test --- packages/core/test/value.test.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/test/value.test.mjs b/packages/core/test/value.test.mjs index ae227e17..1a209623 100644 --- a/packages/core/test/value.test.mjs +++ b/packages/core/test/value.test.mjs @@ -6,6 +6,8 @@ This program is free software: you can redistribute it and/or modify it under th import { describe, it, expect } from 'vitest'; import { map, valued, mul } from '../value.mjs'; +import controls from '../controls.mjs'; +const { n } = controls; describe('Value', () => { it('unionWith', () => { @@ -21,4 +23,8 @@ describe('Value', () => { expect(valued(mul).ap(3).ap(3).value).toEqual(9); expect(valued(3).mul(3).value).toEqual(9); }); + it('union bare numbers for numeral props', () => { + expect(n(3).cutoff(500).add(10).firstCycleValues).toEqual([{ n: 13, cutoff: 510 }]); + expect(n(3).cutoff(500).mul(2).firstCycleValues).toEqual([{ n: 6, cutoff: 1000 }]); + }); });