feat: add a first generic method, square (#10)
All checks were successful
/ test (push) Successful in 10s
All checks were successful
/ test (push) Successful in 10s
Resolves #2. Reviewed-on: #10 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
1a6890f458
commit
05ff078529
7 changed files with 34 additions and 4 deletions
11
src/generic/__test__/arithmetic.spec.js
Normal file
11
src/generic/__test__/arithmetic.spec.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import assert from 'assert'
|
||||
import math from '#nanomath'
|
||||
|
||||
describe('generic arithmetic', () => {
|
||||
it('squares anything', () => {
|
||||
assert.strictEqual(math.square(7), 49)
|
||||
assert.strictEqual(
|
||||
math.square.resolve([math.types.Number]).returns,
|
||||
math.types.Number)
|
||||
})
|
||||
})
|
1
src/generic/all.js
Normal file
1
src/generic/all.js
Normal file
|
@ -0,0 +1 @@
|
|||
export * as arithmetic from './arithmetic.js'
|
8
src/generic/arithmetic.js
Normal file
8
src/generic/arithmetic.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import {onType} from '#core/helpers.js'
|
||||
import {Returns} from '#core/Type.js'
|
||||
import {Any} from '#core/TypePatterns.js'
|
||||
|
||||
export const square = onType(Any, (math, T) => {
|
||||
const mult = math.multiply.resolve([T, T])
|
||||
return Returns(mult.returns, a => mult(a, a))
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue