Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ddcc4 committed Jan 23, 2025
1 parent d765a33 commit f79364e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
76 changes: 37 additions & 39 deletions step-generation/src/commandCreators/compound/mix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
CommandCreator,
CurriedCommandCreator,
} from '../../types'
import { curryCommandCreatorNoPython } from '../../utils/curryCommandCreator'
/** Helper fn to make mix command creators w/ minimal arguments */
export function mixUtil(args: {
pipette: string
Expand Down Expand Up @@ -92,48 +93,45 @@ export function mixUtil(args: {
// If there is no delay, then we can issue a single Python mix() command, so we want to suppresss
// the Python from the individual aspirate dispense commands.
const noDelay = !aspirateDelaySeconds && !dispenseDelaySeconds
const innerCurryCommandCreator = noDelay
? curryCommandCreatorNoPython
: curryCommandCreator

const commands = repeatArray(
[
innerCurryCommandCreator(aspirate, {
pipette,
volume,
labware,
well,
offsetFromBottomMm: aspirateOffsetFromBottomMm,
flowRate: aspirateFlowRateUlSec,
tipRack,
xOffset: aspirateXOffset,
yOffset: aspirateYOffset,
nozzles: null,
}),
...getDelayCommand(aspirateDelaySeconds),
innerCurryCommandCreator(dispense, {
pipette,
volume,
labware,
well,
offsetFromBottomMm: dispenseOffsetFromBottomMm,
flowRate: dispenseFlowRateUlSec,
xOffset: dispenseXOffset,
yOffset: dispenseYOffset,
tipRack,
nozzles: nozzles,
}),
...getDelayCommand(dispenseDelaySeconds),
],
times
)

return [
...(noDelay ? [curryCommandCreator(pythonMixCommand, {})] : []),
...repeatArray(
[
curryCommandCreator(
aspirate,
{
pipette,
volume,
labware,
well,
offsetFromBottomMm: aspirateOffsetFromBottomMm,
flowRate: aspirateFlowRateUlSec,
tipRack,
xOffset: aspirateXOffset,
yOffset: aspirateYOffset,
nozzles: null,
},
noDelay
),
...getDelayCommand(aspirateDelaySeconds),
curryCommandCreator(
dispense,
{
pipette,
volume,
labware,
well,
offsetFromBottomMm: dispenseOffsetFromBottomMm,
flowRate: dispenseFlowRateUlSec,
xOffset: dispenseXOffset,
yOffset: dispenseYOffset,
tipRack,
nozzles: nozzles,
},
noDelay
),
...getDelayCommand(dispenseDelaySeconds),
],
times
),
...commands,
]
}
export const mix: CommandCreator<MixArgs> = (
Expand Down
13 changes: 10 additions & 3 deletions step-generation/src/utils/curryCommandCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import type { CommandCreator, CurriedCommandCreator } from '../types'
* but it is still open to receiving different input states */
export function curryCommandCreator<Args>(
commandCreator: CommandCreator<Args>,
args: Args,
suppressPython?: boolean
args: Args
): CurriedCommandCreator {
return (_invariantContext, _prevRobotState) =>
commandCreator(args, _invariantContext, _prevRobotState)
}

export function curryCommandCreatorNoPython<Args>(
commandCreator: CommandCreator<Args>,
args: Args
): CurriedCommandCreator {
return (_invariantContext, _prevRobotState) => {
const commandCreatorResult = commandCreator(
args,
_invariantContext,
_prevRobotState
)
if (suppressPython && 'python' in commandCreatorResult) {
if ('python' in commandCreatorResult) {
const { python, ...withoutPython } = commandCreatorResult
return withoutPython
}
Expand Down

0 comments on commit f79364e

Please sign in to comment.