You are looking at historical revision 18915 of this page. It may differ significantly from its current revision.

• egg

## combinators

Combinators grab-bag.

## Documentation

### Section Combinators

#### Usage

`(require-extension section-combinators)`

#### left-section

[procedure] (left-section FUNC ARG0 ...) => {{procedure}}

Returns a procedure that partially applies some of its arguments starting from the left.

FUNC a procedure.

ARG0 ... some prefix of the arguments for FUNC.

Returns a partially curried procedure.

#### right-section

[procedure] (right-section FUNC ARG0 ...) => {{procedure}}

Returns a procedure that partially applies some of its arguments starting from the right.

FUNC a procedure.

ARG0 ... some reversed suffix of the arguments for FUNC.

Returns a partially curried procedure.

### Sort Combinators

#### Usage

`(require-extension sort-combinators)`

#### Examples

```(group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4))

(group/key car '((a 1) (a 2) (b 1)))  ;=> '(((a 1) (a 2)) ((b 1)))

(sort '(("a" . 1) ("z" . 3) ("b" . 2)) (make-less-than/key first string-ci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3))```

#### group/key

[procedure] (group/key FUNC LYST [EQUALITY equal?])

Groups a LYST of elements by some key attribute. Uses the single-argument FUNC to retrieve key values & the EQUALITY function to compare them.

The LYST must be in sorted order with respect to the key!

Returns a list of grouped elements.

#### make-less-than/key

[procedure] (make-less-than/key FUNC [LESS-THAN <]) => {{procedure/2}}

Returns a two-argument procedure that uses the single-argument FUNC to retrieve key values & the two-argument LESS-THAN procedure to compare them.

#### make-equal/key

[procedure] (make-equal/key FUNC [EQUAL =]) => {{procedure/2}}

Returns a two-argument procedure that uses the single-argument FUNC to retrieve key values & the two-argument EQUAL procedure to compare them.

### Logical Combinators

#### Usage

`(require-extension logical-combinators)`

#### andf

[procedure] (andf OBJECT...)

Eager version of and.

Returns last (not #f) OBJECT when all OBJECT... are (not #f), #f otherwise.

#### orf

[procedure] (orf OBJECT...)

Eager version of or.

Returns first (not #f) OBJECT, #f otherwise.

### Stack Combinators

#### Usage

`(require-extension stack-combinators)`

C is a combinator function.

F, G and H are function.

X, Y and Z are object.

#### uni

[procedure] (uni X F C) => {{procedure}}

Returns the result of (C (F X)).

[procedure] (uni F C) => {{procedure/1}}
[procedure] (uni C) => {{procedure/1}}
[procedure] (uni) => {{procedure/1}}

Returns a curried procedure.

#### uni2

[procedure] (uni2 X Y F C) => {{procedure}}

Returns the result of (C (F X Y)).

[procedure] (uni2 F C) => {{procedure/2}}
[procedure] (uni2 C) => {{procedure/1}}
[procedure] (uni2) => {{procedure/1}}

Returns a curried procedure.

#### uni3

[procedure] (uni3 X Y Z F C) => {{procedure}}

Returns the result of (C (F X Y Z)).

[procedure] (uni3 F C) => {{procedure/3}}
[procedure] (uni3 C) => {{procedure/1}}
[procedure] (uni3) => {{procedure/1}}

Returns a curried procedure.

#### bi

[procedure] (bi X F G C) => {{procedure}}

Returns the result of (C (F X) (G X)).

[procedure] (bi F G C) => {{procedure/1}}
[procedure] (bi F G) => {{procedure/1}}
[procedure] (bi C) => {{procedure/2}}
[procedure] (bi) => {{procedure/1}}

Returns a curried procedure.

#### bi2

[procedure] (bi2 X Y F G C) => {{procedure}}

Returns the result of (C (F X Y) (G X Y)).

[procedure] (bi2 F G C) => {{procedure/2}}
[procedure] (bi2 F G) => {{procedure/1}}
[procedure] (bi2 C) => {{procedure/2}}
[procedure] (bi2) => {{procedure/1}}

Returns a curried procedure.

#### bi3

[procedure] (bi3 X Y Z F G C) => {{procedure}}

Returns the result of (C (F X Y Z) (G X Y Z)).

[procedure] (bi3 F G C) => {{procedure/3}}
[procedure] (bi3 F G) => {{procedure/1}}
[procedure] (bi3 C) => {{procedure/2}}
[procedure] (bi3) => {{procedure/1}}

Returns a curried procedure.

#### bi@

[procedure] (bi@ X Y F C) => {{procedure}}

Returns the result of (C (F X) (F Y)).

[procedure] (bi@ F C) => {{procedure/2}}

Returns a curried procedure.

#### tri

[procedure] (tri X F G H C) => {{procedure}}

Returns the result of (C (F X) (G X) (H X)).

[procedure] (tri F G H C) => {{procedure/1}}
[procedure] (tri F G H) => {{procedure/1}}
[procedure] (tri C) => {{procedure/3}}
[procedure] (tri) => {{procedure/1}}

Returns a curried procedure.

#### tri2

[procedure] (tri2 X Y F G H C) => {{procedure}}

Returns the result of (C (F X Y) (G X Y) (H X Y)).

[procedure] (tri2 F G H C) => {{procedure/2}}
[procedure] (tri2 F G H) => {{procedure/1}}
[procedure] (tri2 C) => {{procedure/3}}
[procedure] (tri2) => {{procedure/1}}

Returns a curried procedure.

#### tri3

[procedure] (tri3 X Y Z F G H C) => {{procedure}}

Returns the result of (C (F X Y Z) (G X Y Z) (H X Y Z)).

[procedure] (tri3 F G H C) => {{procedure/3}}
[procedure] (tri3 F G H) => {{procedure/1}}
[procedure] (tri3 C) => {{procedure/3}}
[procedure] (tri3) => {{procedure/1}}

Returns a curried procedure.

#### tri@

[procedure] (tri@ X Y Z F G H C) => {{procedure}}

Returns the result of (C (F X) (G Y) (H Z)).

[procedure] (tri@ F G H C) => {{procedure/3}}

Returns a curried procedure.

#### dip

[procedure] (dip X Y F C) => {{procedure}}

Returns the result of (C (F X) Y).

[procedure] (dip F C) => {{procedure/2}}

Returns a curried procedure.

#### dup

[procedure] (dup X C) => {{procedure}}

Returns the result of (C X X).

[procedure] (dup C) => {{procedure/1}}

Returns a curried procedure.

#### dupd

[procedure] (dupd X Y C) => {{procedure}}

Returns the result of (C X X Y).

[procedure] (dupd C) => {{procedure/2}}

Returns a curried procedure.

#### swap

[procedure] (swap X Y C) => {{procedure}}

Returns the result of (C Y X).

[procedure] (swap C) => {{procedure/2}}

Returns a curried procedure.

#### drop

<procedure>(drop X C)< => procedure/procedure>

Returns the result of (C).

[procedure] (drop C) => {{procedure/1}}

Returns a curried procedure.

#### drop/2

[procedure] (drop/2 X Y C) => {{procedure}}

Returns the result of (C X).

[procedure] (drop/2 C) => {{procedure/2}}

Returns a curried procedure.

## Notes

• Inspired by e-mail conversations with Graham Fawcett in Feb '08.
• The left-section and right-section are from Chicken core data-structures.

kon lovett

1.1.0