Skip to content

Commit 8fc3245

Browse files
authored
Merge pull request #19 from mkantor/prepend-append
Rename `atom.concatenate` to `atom.append`, add `atom.prepend`
2 parents df55490 + 0ac2c12 commit 8fc3245

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

src/end-to-end.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ testCases(endToEnd, code => code)('end-to-end tests', [
7575
either.makeRight('output'),
7676
],
7777
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
78-
[':{atom concatenate}(a)(b)', either.makeRight('ba')],
79-
[
80-
':flow({ :atom.concatenate(a) :atom.concatenate(b) })(z)',
81-
either.makeRight('zab'),
82-
],
78+
[':{atom prepend}(a)(b)', either.makeRight('ab')],
79+
[':flow({ :atom.append(a) :atom.append(b) })(z)', either.makeRight('zab')],
8380
[
8481
`{
8582
// foo: bar

src/language/semantics/prelude.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,32 +496,72 @@ export const prelude: ObjectNode = makeObjectNode({
496496
}),
497497

498498
atom: makeObjectNode({
499-
concatenate: preludeFunction(
500-
['atom', 'concatenate'],
499+
append: preludeFunction(
500+
['atom', 'append'],
501501
{
502502
parameter: types.atom,
503503
return: makeFunctionType('', {
504504
parameter: types.atom,
505505
return: types.atom,
506506
}),
507507
},
508-
string2 =>
508+
atomToAppend =>
509509
either.makeRight(
510510
makeFunctionNode(
511511
{
512512
parameter: types.atom,
513513
return: types.atom,
514514
},
515-
serializePartiallyAppliedFunction(['atom', 'concatenate'], string2),
515+
serializePartiallyAppliedFunction(['atom', 'append'], atomToAppend),
516516
option.none,
517-
string1 => {
518-
if (typeof string1 !== 'string' || typeof string1 !== 'string') {
517+
atomToAppendTo => {
518+
if (
519+
typeof atomToAppend !== 'string' ||
520+
typeof atomToAppendTo !== 'string'
521+
) {
522+
return either.makeLeft({
523+
kind: 'panic',
524+
message: 'append received a non-atom argument',
525+
})
526+
} else {
527+
return either.makeRight(atomToAppendTo + atomToAppend)
528+
}
529+
},
530+
),
531+
),
532+
),
533+
prepend: preludeFunction(
534+
['atom', 'prepend'],
535+
{
536+
parameter: types.atom,
537+
return: makeFunctionType('', {
538+
parameter: types.atom,
539+
return: types.atom,
540+
}),
541+
},
542+
atomToPrepend =>
543+
either.makeRight(
544+
makeFunctionNode(
545+
{
546+
parameter: types.atom,
547+
return: types.atom,
548+
},
549+
serializePartiallyAppliedFunction(
550+
['atom', 'prepend'],
551+
atomToPrepend,
552+
),
553+
option.none,
554+
atomToPrependTo => {
555+
if (
556+
typeof atomToPrepend !== 'string' ||
557+
typeof atomToPrependTo !== 'string'
558+
) {
519559
return either.makeLeft({
520560
kind: 'panic',
521-
message: 'concatenate received a non-atom argument',
561+
message: 'prepend received a non-atom argument',
522562
})
523563
} else {
524-
return either.makeRight(string1 + string2)
564+
return either.makeRight(atomToPrepend + atomToPrependTo)
525565
}
526566
},
527567
),

0 commit comments

Comments
 (0)