On this page:
2.1 Functions
values->
thunk<-
flip
twice
$$
>>
<<
>>*
<<*
id
:  :
:  :  *
+  +
..
&&
||
$
2.2 Lists
member-of
free-member-of
7.9

2 The Prelude

 (require algebraic/prelude) package: algebraic

The bindings documented in this section are provided by algebraic/prelude and algebraic/racket/base. These functions and function aliases add consistency to the functional Racket programming experience and encourage compact code. They are used extensively throughout the collection.

In addition to the bindings documented below, this module re-provides Racket’s const and negate functions.

2.1 Functions

syntax

(values-> f expr)

Applies f to the values produced by expr.

Example:
> (values-> + (values 1 2 3))

6

procedure

(thunk<- x ...)  (-> any)

  x : any/c
Returns a thunk that produces the values determined by the xs.

Example:
> ((thunk<- (+ 1 2) (+ 3 4)))

3

7

procedure

(flip f)  procedure?

  f : procedure?
Returns a variadic function that behaves like f with its first two arguments swapped.

Example:
> ((flip -) 10 2 1)

-9

procedure

(twice f)  procedure?

  f : procedure?
Returns a function that composes f with itself, equivalent to (.. f f).

Example:
> ((twice add1) 1)

3

procedure

($$ f x ...)  any

  f : procedure?
  x : any/c
Applies f to the xs.

Equivalent to (λ (f x ...) ($ f (list x ...))).

Example:
> ($$ + 1 2 3)

6

procedure

(>> f x ...)  procedure?

  f : procedure?
  x : any/c
Returns a left-curried version of f.

The >> function does not self-curry. Use >>* to

Example:
> ((>> list 1 2) (list 3 4) 5 6)

'(1 2 (3 4) 5 6)

procedure

(<< f x ...)  procedure?

  f : procedure?
  x : any/c
Returns a right-curried version of f.

The << function, unlike curryr, is not self-curried.

Example:
> ((<< list 1 2) (list 3 4) 5 6)

'((3 4) 5 6 1 2)

procedure

(>>* f)  (-> any/c ... procedure?)

  f : procedure?
Explicit self-curry.

Equivalent to (curry f).

Example:
> (((>>* list) 1 2) 3 4)

'(1 2 3 4)

procedure

(<<* f)  (-> any/c ... procedure?)

  f : procedure?
Explicit self-curryr.

Equivalent to (curryr f).

Example:
> (((<<* list) 1 2) 3 4)

'(3 4 1 2)

value

id : procedure? = values

value

:: : procedure? = cons

value

::* : procedure? = list*

value

++ : procedure? = append

value

.. : procedure? = compose

value

&& : procedure? = conjoin

value

|| : procedure? = disjoin

value

$ : procedure? = apply

Short names for common functions.

2.2 Lists

procedure

(member-of v ...)  (-> any/c (or/c list? #f))

  v : any/c
Returns a unary function that locates the first element of (v ...) that is equal? to its argument. If such an element exists, the tail of (v ...) starting with that element is returned. Otherwise, the result is #f.

Examples:
> ((member-of 1 2 3 4) 2)

'(2 3 4)

> ((member-of 1 2 3 4) 9)

#f

procedure

(free-member-of x ...)  (-> identifier? (or/c list? #f))

  x : identifier?
Like member-of, but finds an element using free-identifier=?.

Examples:
> ((free-member-of #'x #'y) #'x)

'(#<syntax:eval:13:0 x> #<syntax:eval:13:0 y>)

> ((free-member-of #'x #'y) #'a)

#f